Add more docstrings and improve quit_prompt

This commit is contained in:
Christopher Thompson 2020-10-10 00:13:16 -04:00
parent 14e136f80c
commit 5bcad6a305

View file

@ -1,3 +1,4 @@
import sys
import csv import csv
import time import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
@ -15,6 +16,8 @@ INTERRUPTED_MIN = 1 # Minimum minutes to ask to record an interrupted Pomodoro
def pomodoro_prompt_plan(whatdid = ''): def pomodoro_prompt_plan(whatdid = ''):
""" Ask about what task will be worked on (showing last thing worked on)
"""
title = "What're you gonna do?" title = "What're you gonna do?"
text = '' text = ''
# Instead of repeating this, i'd prefer a clean interface with the ability to get back # Instead of repeating this, i'd prefer a clean interface with the ability to get back
@ -31,6 +34,8 @@ def pomodoro_prompt_plan(whatdid = ''):
return whatnext return whatnext
def pomodoro_prompt_report(whatnext): def pomodoro_prompt_report(whatnext):
""" Ask what task was completed, showing the last task claimed to be being worked on
"""
title = "What'd you do?" title = "What'd you do?"
text = '' text = ''
if whatnext: if whatnext:
@ -42,16 +47,20 @@ def pomodoro_prompt_report(whatnext):
return whatdid return whatdid
def quit_prompt(): def quit_prompt():
""" Confirm exit or start a new pomodoro
"""
print('\nPress p to start a new pomodoro, q to quit') print('\nPress p to start a new pomodoro, q to quit')
choice = input('p/q: ').strip() choice = input('p/q: ').strip().lower()
if choice.lower() in ('p', 'pomodoro'): if choice in ('p', 'pomodoro'):
return return
elif choice.lower() in ('q', 'quit', 'exit'): elif choice in ('q', 'quit', 'exit'):
quit() sys.exit(0)
else: else:
quit_prompt() quit_prompt()
def log_step(text, utc_start, end_section=False): def log_step(text, utc_start, end_section=False):
""" Write detailed log of all events
"""
eastern = timezone('US/Eastern') eastern = timezone('US/Eastern')
start = utc_start.astimezone(eastern) start = utc_start.astimezone(eastern)
timelog_path = 'log/' + str(start.year) + '-' + format(start.month, '02') + '-' + format(start.day, '02') + '.log' timelog_path = 'log/' + str(start.year) + '-' + format(start.month, '02') + '-' + format(start.day, '02') + '.log'
@ -64,6 +73,8 @@ def log_step(text, utc_start, end_section=False):
def record_task(whatdid, start, end=None): def record_task(whatdid, start, end=None):
""" Record completed pomodoro to CSV
"""
if end is None: if end is None:
end = datetime.now(pytz.utc) end = datetime.now(pytz.utc)
with open('timelog.csv', 'a', newline='') as csvfile: with open('timelog.csv', 'a', newline='') as csvfile: