From 42191e8927e6f0f7c9750d1f3440d0802d2d41b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Mon, 6 Jul 2020 08:43:56 -0400 Subject: [PATCH] Get our log-writing on --- pomodoroprompt.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/pomodoroprompt.py b/pomodoroprompt.py index 6988453..e45ae2a 100644 --- a/pomodoroprompt.py +++ b/pomodoroprompt.py @@ -6,20 +6,33 @@ from pathlib import Path import pytz import zenipy -WORK_MIN = .1 -SHORT_MIN = .1 +WORK_MIN = 1 +SHORT_MIN = 1 LONG_MIN = 15 def pomodoro_prompt_plan(whatdid = ''): - whatnext = zenipy.zenipy.entry(text="What're you gonna do?", placeholder=whatdid, title='Pomodoro Prompt: Plan') + title = "What're you gonna do?" + text = '' + # Instead of repeating this, i'd prefer a clean interface with the ability to get back + # the placeholder text with 'esc' or up arrow or something. But i'm not up for building + # my own interface, so here's what we get. NOTE: If we can do system notifications that + # when clicked will focus the terminal running pomodoro prompt, that would be even better + # than these pop-up GUI notifications/text entry. + if whatdid: + text = "\n\n(Last thing you did: " + whatdid + ')\n' + whatnext = zenipy.zenipy.entry(text=text, placeholder=whatdid, title=title) # Pressing cancel returns None, but we want to just treat it as an empty string. if whatnext is None: whatnext = '' return whatnext def pomodoro_prompt_report(whatnext): - whatdid = zenipy.zenipy.entry(text="What'd you do?", placeholder=whatnext, title='Pomodoro Prompt: Report') + title = "What'd you do?" + text = '' + if whatnext: + text = "\n\n(What you said you'd do: " + whatnext + ')\n' + whatdid = zenipy.zenipy.entry(text=text, placeholder=whatnext, title=title) # Pressing cancel returns None, but we want to just treat it as an empty string. if whatdid is None: whatdid = '' @@ -35,13 +48,15 @@ def quit_prompt(): else: quit_prompt() -def log_step(text, start): +def log_step(text, start, end_section=False): timelog_path = 'log/' + str(start.year) + '-' + format(start.month, '02') + '-' + format(start.day, '02') + '.log' timelog_file = Path(timelog_path) timelog_file.touch(exist_ok=True) with timelog_file.open('a') as timelog: + timelog.write(text) + if end_section: + timelog.write('/n/n') - return def record_task(whatdid, start, end=None): if end is None: @@ -50,6 +65,9 @@ def record_task(whatdid, start, end=None): timewriter = csv.writer(csvfile) timewriter.writerow([start, end, whatdid]) +def str_minutes(time_diff): + return str(time_diff).split('.')[0] + def main(): whatdid = '' @@ -58,6 +76,7 @@ def main(): start = datetime.now(pytz.utc) end = start + timedelta(minutes=WORK_MIN, seconds=0) + log_step('Start with plan: ' + whatnext, start) try: print('Task -', whatnext) while datetime.now(pytz.utc) <= end: @@ -66,20 +85,23 @@ def main(): time.sleep(1) whatdid = pomodoro_prompt_report(whatnext) record_task(whatdid, start) + log_step('Completed pomodoro: ' + whatdid, start, True) continue except KeyboardInterrupt: time_spent = datetime.now(pytz.utc) - start - print('\n{} time spent, save?'.format(str(time_spent).split('.')[0])) + print('\n{} time spent, save?'.format(str_minutes(time_spent)) choice = input('[y]/n: ').strip() if choice.lower() in ('y', 'yes', ''): whatdid = pomodoro_prompt_report(whatnext) record_task(whatdid, start) + log_step('Incomplete (' + str_minutes(time_spent) + ') pomodoro: ' + whatdid, start, True) else: quit_prompt() else: print('What did you break?') # If we somehow end up here, try a last-ditch effort to save. record_task('Incomplete, interrupted task:' + whatnext, start) + log_step('Incomplete, interrupted task:' + whatnext, start, True) if __name__ == '__main__':