When trying to put a time report together for a client, to attach to an invoice, I figured getting a CSV from toggl would be a good start. As it turns out, their CSV is not entirely suitable for importing in Numbers.
This script fixes the CSV up in a few ways:
- it puts a single quote character in front of all timestamp fields - without it, Numbers will interpret the dates and, for me, it is confused about day field vs. month field
- it sorts the CSV by start time, ascending instead of descending
Code: (download here)
The script may be useful for Excel users too, I have not checked.
#!/usr/bin/env python import csv import sys import operator r = csv.reader(sys.stdin) rows= for row in r: row = "'%s" % row row = "'%s" % row row = "'%s" % row rows.append(row) rows = [rows] + sorted( rows[1:], key=operator.itemgetter(5) ) w = csv.writer(sys.stdout) for row in rows: w.writerow(row)