2020-07-05 19:41:04 +00:00
|
|
|
import csv
|
2020-07-05 16:55:18 +00:00
|
|
|
import time
|
2020-07-05 19:41:04 +00:00
|
|
|
from datetime import datetime, timedelta
|
2020-07-06 03:40:12 +00:00
|
|
|
from pathlib import Path
|
2020-07-05 16:55:18 +00:00
|
|
|
|
|
|
|
import pytz
|
|
|
|
import zenipy
|
|
|
|
|
2020-07-05 19:41:04 +00:00
|
|
|
WORK_MIN = .1
|
|
|
|
SHORT_MIN = .1
|
2020-07-05 16:55:18 +00:00
|
|
|
LONG_MIN = 15
|
|
|
|
|
|
|
|
|
2020-07-05 17:26:38 +00:00
|
|
|
def pomodoro_prompt_plan(whatdid = ''):
|
2020-07-05 23:05:40 +00:00
|
|
|
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 = ''
|
2020-07-05 20:00:19 +00:00
|
|
|
return whatnext
|
2020-07-05 17:26:38 +00:00
|
|
|
|
|
|
|
def pomodoro_prompt_report(whatnext):
|
2020-07-05 23:05:40 +00:00
|
|
|
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 = ''
|
2020-07-05 20:00:19 +00:00
|
|
|
return whatdid
|
2020-07-05 16:55:18 +00:00
|
|
|
|
2020-07-06 01:45:53 +00:00
|
|
|
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()
|
|
|
|
|
2020-07-06 03:40:12 +00:00
|
|
|
def log_step(text, start):
|
|
|
|
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:
|
|
|
|
|
|
|
|
return
|
2020-07-06 01:45:53 +00:00
|
|
|
|
2020-07-05 19:41:04 +00:00
|
|
|
def record_task(whatdid, start, end=None):
|
|
|
|
if end is None:
|
|
|
|
end = datetime.now(pytz.utc)
|
2020-07-06 03:40:12 +00:00
|
|
|
with open('timelog.csv', 'a', newline='') as csvfile:
|
2020-07-05 19:41:04 +00:00
|
|
|
timewriter = csv.writer(csvfile)
|
|
|
|
timewriter.writerow([start, end, whatdid])
|
2020-07-05 16:55:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2020-07-05 23:22:29 +00:00
|
|
|
whatdid = ''
|
|
|
|
while True:
|
|
|
|
whatnext = pomodoro_prompt_plan(whatdid)
|
2020-07-05 17:26:38 +00:00
|
|
|
|
2020-07-05 23:22:29 +00:00
|
|
|
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)
|
2020-07-05 19:41:04 +00:00
|
|
|
whatdid = pomodoro_prompt_report(whatnext)
|
|
|
|
record_task(whatdid, start)
|
2020-07-05 23:22:29 +00:00
|
|
|
continue
|
|
|
|
except KeyboardInterrupt:
|
2020-07-06 00:50:42 +00:00
|
|
|
time_spent = datetime.now(pytz.utc) - start
|
|
|
|
print('\n{} time spent, save?'.format(str(time_spent).split('.')[0]))
|
2020-07-05 23:22:29 +00:00
|
|
|
choice = input('[y]/n: ').strip()
|
|
|
|
if choice.lower() in ('y', 'yes', ''):
|
|
|
|
whatdid = pomodoro_prompt_report(whatnext)
|
|
|
|
record_task(whatdid, start)
|
2020-07-06 01:45:53 +00:00
|
|
|
else:
|
|
|
|
quit_prompt()
|
2020-07-05 23:22:29 +00:00
|
|
|
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)
|
2020-07-05 19:41:04 +00:00
|
|
|
|
|
|
|
|
2020-07-05 16:55:18 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|