Get our log-writing on
This commit is contained in:
parent
b2d774911f
commit
42191e8927
1 changed files with 29 additions and 7 deletions
|
@ -6,20 +6,33 @@ from pathlib import Path
|
||||||
import pytz
|
import pytz
|
||||||
import zenipy
|
import zenipy
|
||||||
|
|
||||||
WORK_MIN = .1
|
WORK_MIN = 1
|
||||||
SHORT_MIN = .1
|
SHORT_MIN = 1
|
||||||
LONG_MIN = 15
|
LONG_MIN = 15
|
||||||
|
|
||||||
|
|
||||||
def pomodoro_prompt_plan(whatdid = ''):
|
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.
|
# Pressing cancel returns None, but we want to just treat it as an empty string.
|
||||||
if whatnext is None:
|
if whatnext is None:
|
||||||
whatnext = ''
|
whatnext = ''
|
||||||
return whatnext
|
return whatnext
|
||||||
|
|
||||||
def pomodoro_prompt_report(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.
|
# Pressing cancel returns None, but we want to just treat it as an empty string.
|
||||||
if whatdid is None:
|
if whatdid is None:
|
||||||
whatdid = ''
|
whatdid = ''
|
||||||
|
@ -35,13 +48,15 @@ def quit_prompt():
|
||||||
else:
|
else:
|
||||||
quit_prompt()
|
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_path = 'log/' + str(start.year) + '-' + format(start.month, '02') + '-' + format(start.day, '02') + '.log'
|
||||||
timelog_file = Path(timelog_path)
|
timelog_file = Path(timelog_path)
|
||||||
timelog_file.touch(exist_ok=True)
|
timelog_file.touch(exist_ok=True)
|
||||||
with timelog_file.open('a') as timelog:
|
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):
|
def record_task(whatdid, start, end=None):
|
||||||
if end is None:
|
if end is None:
|
||||||
|
@ -50,6 +65,9 @@ def record_task(whatdid, start, end=None):
|
||||||
timewriter = csv.writer(csvfile)
|
timewriter = csv.writer(csvfile)
|
||||||
timewriter.writerow([start, end, whatdid])
|
timewriter.writerow([start, end, whatdid])
|
||||||
|
|
||||||
|
def str_minutes(time_diff):
|
||||||
|
return str(time_diff).split('.')[0]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
whatdid = ''
|
whatdid = ''
|
||||||
|
@ -58,6 +76,7 @@ def main():
|
||||||
|
|
||||||
start = datetime.now(pytz.utc)
|
start = datetime.now(pytz.utc)
|
||||||
end = start + timedelta(minutes=WORK_MIN, seconds=0)
|
end = start + timedelta(minutes=WORK_MIN, seconds=0)
|
||||||
|
log_step('Start with plan: ' + whatnext, start)
|
||||||
try:
|
try:
|
||||||
print('Task -', whatnext)
|
print('Task -', whatnext)
|
||||||
while datetime.now(pytz.utc) <= end:
|
while datetime.now(pytz.utc) <= end:
|
||||||
|
@ -66,20 +85,23 @@ def main():
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
whatdid = pomodoro_prompt_report(whatnext)
|
whatdid = pomodoro_prompt_report(whatnext)
|
||||||
record_task(whatdid, start)
|
record_task(whatdid, start)
|
||||||
|
log_step('Completed pomodoro: ' + whatdid, start, True)
|
||||||
continue
|
continue
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
time_spent = datetime.now(pytz.utc) - start
|
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()
|
choice = input('[y]/n: ').strip()
|
||||||
if choice.lower() in ('y', 'yes', ''):
|
if choice.lower() in ('y', 'yes', ''):
|
||||||
whatdid = pomodoro_prompt_report(whatnext)
|
whatdid = pomodoro_prompt_report(whatnext)
|
||||||
record_task(whatdid, start)
|
record_task(whatdid, start)
|
||||||
|
log_step('Incomplete (' + str_minutes(time_spent) + ') pomodoro: ' + whatdid, start, True)
|
||||||
else:
|
else:
|
||||||
quit_prompt()
|
quit_prompt()
|
||||||
else:
|
else:
|
||||||
print('What did you break?')
|
print('What did you break?')
|
||||||
# If we somehow end up here, try a last-ditch effort to save.
|
# If we somehow end up here, try a last-ditch effort to save.
|
||||||
record_task('Incomplete, interrupted task:' + whatnext, start)
|
record_task('Incomplete, interrupted task:' + whatnext, start)
|
||||||
|
log_step('Incomplete, interrupted task:' + whatnext, start, True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue