# HG changeset patch # User Sascha L. Teichmann # Date 1220989380 -7200 # Node ID 0bb0100b2c8dea127e464cbb0043fb96a976ab53 # Parent 83f99008a3f9d235aa492386edacb644a3c1f504 Added a script to sort zeiterfassung.txt files by date. Useful to merge them. diff -r 83f99008a3f9 -r 0bb0100b2c8d ChangeLog --- a/ChangeLog Tue Aug 12 15:01:11 2008 +0200 +++ b/ChangeLog Tue Sep 09 21:43:00 2008 +0200 @@ -1,3 +1,9 @@ +2008-09-09 Sascha L. Teichmann + + * contrib/zeitsort: New. Sorts a zeiterfassung.txt file by + the dates in the lines. Useful to merge larger chunks + by simply append them and sort the result afterwards. + 2008-08-12 Sascha L. Teichmann * getan: When assiging a name to an anonym task remove and diff -r 83f99008a3f9 -r 0bb0100b2c8d contrib/zeitsort --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/zeitsort Tue Sep 09 21:43:00 2008 +0200 @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# zeitsort +# -------- +# (c) 2008 by Sascha L. Teichmann +# +# Simple script which sorts lines of zeiterfassung.txt files by date. +# +# This is Free Software licensed under the terms of GPLv3 or later. +# For details see LICENSE coming with the source of 'getan'. +# + +import sys +import re + +from datetime import date + +DATE = re.compile("(\d\d)\.(\d\d)\.(\d\d\d\d)") + +def date_cmp(a, b): + ma = DATE.search(a) + mb = DATE.search(b) + if not ma and not mb: return cmp(a, b) + if ma and not mb: return -1 + if not ma and mb: return +1 + da = date(int(ma.group(3)), int(ma.group(2)), int(ma.group(1))) + db = date(int(mb.group(3)), int(mb.group(2)), int(mb.group(1))) + return cmp(da, db) + +def main(): + all = [] + while True: + line = sys.stdin.readline() + if not line: break + if not DATE.search(line): + # handle multi lines + if not all: all.append(line) + else: all[-1] += line + else: + all.append(line) + all.sort(date_cmp) + sys.stdout.write(''.join(all)) + sys.stdout.flush() + +if __name__ == '__main__': + main() + +# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: