import csv import time from datetime import datetime, timedelta import pytz import zenipy 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') # 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') # Pressing cancel returns None, but we want to just treat it as an empty string. if whatdid is None: whatdid = '' return whatdid def quit_prompt(): print('\nPress p to start a new pomodoro, q to quit') choice = input('p/q: ').strip() if choice.lower() in ('p', 'pomodoro'): return elif choice.lower() in ('q', 'quit', 'exit'): quit() else: quit_prompt() def log_step(text): # timelog.touch(exist_ok=True) # with timelog.open('r+') as f: # pp = PomodoroPrompt(timelog=f) return def record_task(whatdid, start, end=None): if end is None: end = datetime.now(pytz.utc) with open('timelog.csv', 'w', newline='') as csvfile: timewriter = csv.writer(csvfile) timewriter.writerow([start, end, whatdid]) def main(): whatdid = '' while True: whatnext = pomodoro_prompt_plan(whatdid) start = datetime.now(pytz.utc) end = start + timedelta(minutes=WORK_MIN, seconds=0) try: print('Task -', whatnext) while datetime.now(pytz.utc) <= end: to_go = end-datetime.now(pytz.utc) print('\r', str(to_go).split('.')[0], sep='', end='') time.sleep(1) whatdid = pomodoro_prompt_report(whatnext) record_task(whatdid, start) continue except KeyboardInterrupt: time_spent = datetime.now(pytz.utc) - start print('\n{} time spent, save?'.format(str(time_spent).split('.')[0])) choice = input('[y]/n: ').strip() if choice.lower() in ('y', 'yes', ''): whatdid = pomodoro_prompt_report(whatnext) record_task(whatdid, start) 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) if __name__ == '__main__': main()