Add main function to hms.py.

This commit is contained in:
Ethan Dalool 2020-07-20 18:04:12 -07:00
parent 3a5e160504
commit 16b1d85dbd

View file

@ -1,4 +1,5 @@
import math
import sys
def hms_to_seconds(hms):
'''
@ -34,3 +35,18 @@ def seconds_to_hms(seconds):
parts.append(seconds)
hms = ':'.join(f'{part:02d}' for part in parts)
return hms
def main(args):
from voussoirkit import pipeable
for line in pipeable.go(args, strip=True, skip_blank=True):
if ':' in line:
line = hms_to_seconds(line)
else:
line = float(line)
if line > 60:
line = seconds_to_hms(line)
pipeable.output(f'{line}')
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))