Last active
May 16, 2016 14:24
-
-
Save marksteve/fed69cc86cf8f0c0e104af55516a644d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Usage: | |
watson log > watson-log | |
curl https://gist.githubusercontent.com/marksteve/fed69cc86cf8f0c0e104af55516a644d/raw/85b460cceea45236ac400df716985ef996565c92/watson-csv-export.py | python - watson-log | |
""" | |
import csv | |
import fileinput | |
import re | |
import sys | |
date_pat = re.compile('^(.+)\((.+)\)$') | |
date, duration, task = None, None, None | |
writer = csv.DictWriter(sys.stdout, fieldnames=[ | |
'Date', 'Duration', 'Task', | |
]) | |
writer.writeheader() | |
for l in fileinput.input(): | |
if l.startswith('\t'): | |
secs = l[33:36].strip() | |
mins = l[29:32].strip() or '00' | |
hours = l[24:28].strip() or '0' | |
duration = '{}:{}:{}'.format(hours, mins, secs) | |
task = l[37:].strip() | |
writer.writerow({ | |
'Date': date, | |
'Duration': duration, | |
'Task': task, | |
}) | |
else: | |
m = date_pat.match(l) | |
if m: | |
date, _ = m.groups() | |
date = date.strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment