Skip to content

Instantly share code, notes, and snippets.

@phrz
Last active January 25, 2019 15:57
Show Gist options
  • Save phrz/5f3121cf569b33ef33f7064c67d7522e to your computer and use it in GitHub Desktop.
Save phrz/5f3121cf569b33ef33f7064c67d7522e to your computer and use it in GitHub Desktop.
Tool to sum hours sheet at work
import time
print('SCHEDULE ENTRY', '='*50, sep='\n')
print('[Input schedule lines "HHMM <task>". Ends when <task> is "end"]\n')
sums = {}
last_start = None
t = time.mktime
while True:
try:
line = input()
except EOFError:
break
if line == '':
continue
start, task = line.split(' ', 1)
start = time.strptime(start, '%H%M')
if last_start:
sums[last_task] = t(start) - t(last_start) + sums.get(last_task, 0.0)
last_start, last_task = start, task
if task == 'end':
break
print('\nSummary:',*[f'{seconds/(60*60)} {task}' for task, seconds in sums.items()], sep='\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment