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)
#!/usr/bin/env python
import csv
import sys
import operator
r = csv.reader(sys.stdin)
rows=[]
for row in r:
row[5] = "'%s" % row[5]
row[6] = "'%s" % row[6]
row[7] = "'%s" % row[7]
rows.append(row)
rows = [rows[0]] + sorted(rows[1:], key=operator.itemgetter(5))
w = csv.writer(sys.stdout)
for row in rows:
w.writerow(row)
The script may be useful for Excel users too, I have not checked.