Skip to content

Instantly share code, notes, and snippets.

@phrz
Last active January 25, 2019 15:57
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 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 = lambda s: int(s[:2])*60*60 + int(s[2:4])*60 # HHMM to seconds since previous 00:00
while True:
try:
line = input()
except EOFError:
break
if line == '':
continue
start, task = line.split(' ', 1)
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