Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import re
import sys
from decimal import Decimal
def in_seconds(time_str):
hour, minute = map(int, time_str.split(':'))
return hour * 60 * 60 + minute * 60
def seconds_to_hours(seconds):
return seconds / 60 / 60
def minus_reverse(a, b):
return b - a
def no_zero_decimal(num):
if num.is_integer():
return str(int(num))
return str(num)
with open(sys.argv[1]) as f:
s =
line_hours = [
minus_reverse(*(in_seconds(time_str) for time_str in rng.split('-')))
for rng in re.compile('-'.join(['[0-9]{1,2}:[0-9]{2}'] * 2)).findall(line)))
for line in re.compile(' *- *').sub('-', s).splitlines()
for line, hours in zip(s.splitlines(), line_hours):
if hours == 0:
print(f'{line} ({no_zero_decimal(hours)} hrs)')
dollars = Decimal(sys.argv[2]) * sum(map(Decimal, line_hours))
print(f'Total hours: {sum(line_hours)} hrs = ${dollars}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.