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.

Revisions

  1. phrz revised this gist Jan 25, 2019. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions work.py
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@

    sums = {}
    last_start = None
    t = time.mktime
    t = lambda s: int(s[:2])*60*60 + int(s[2:4])*60 # HHMM to seconds since previous 00:00

    while True:
    try:
    @@ -15,7 +15,6 @@
    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
  2. phrz created this gist Jan 25, 2019.
    25 changes: 25 additions & 0 deletions work.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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')