Skip to content

Instantly share code, notes, and snippets.

@marksteve
Last active May 16, 2016 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marksteve/fed69cc86cf8f0c0e104af55516a644d to your computer and use it in GitHub Desktop.
Save marksteve/fed69cc86cf8f0c0e104af55516a644d to your computer and use it in GitHub Desktop.
"""
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