Factor out countdown timer (and add another docstring)

This commit is contained in:
Christopher Thompson 2020-10-10 00:14:22 -04:00
parent 4e39644b00
commit dd3031fcc3

View file

@ -84,8 +84,17 @@ def record_task(whatdid, start, end=None):
timewriter.writerow([start, end, whatdid])
def str_minutes(time_diff):
""" Return at least whole seconds from a time difference
"""
return str(time_diff).split('.')[0]
def countdown_to(until):
""" Display a timer counting down to until
"""
while datetime.now(pytz.utc) <= until:
to_go = until-datetime.now(pytz.utc)
print('\r', str_minutes(to_go), sep='', end='')
time.sleep(1)
def main():
whatdid = ''
@ -97,10 +106,7 @@ def main():
log_step('Start with plan: ' + whatnext, start)
try:
print('Working on: ', whatnext)
while datetime.now(pytz.utc) <= end:
to_go = end-datetime.now(pytz.utc)
print('\r', str_minutes(to_go), sep='', end='')
time.sleep(1)
countdown_to(end)
playsound('res/timesup.aac')
whatdid = pomodoro_prompt_report(whatnext)
record_task(whatdid, start)
@ -111,10 +117,7 @@ def main():
# We're taking a break. Clear out task start/end times.
start = None
end = datetime.now(pytz.utc) + timedelta(minutes=SHORT_MIN)
while datetime.now(pytz.utc) <= end:
to_go = end-datetime.now(pytz.utc)
print('\r', str_minutes(to_go), sep='', end='')
time.sleep(1)
countdown_to(end)
playsound('res/timesup.aac')
continue
except KeyboardInterrupt: