Enhanced directory-creating, CSV-header initializing still-seems-to-work
This commit is contained in:
parent
fede7fabe2
commit
810712166d
1 changed files with 11 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
import csv
|
||||
import os
|
||||
# This is a local script are we supposed to indicate that?
|
||||
import prompt_window
|
||||
import time
|
||||
|
@ -53,21 +54,26 @@ def quit_prompt():
|
|||
def log_step(text, utc_start, end_section=False):
|
||||
""" Write detailed log of all events
|
||||
"""
|
||||
timelog_file = Path(timelog_path(ext='log', daily=True))
|
||||
timelog_file = Path(prepare_file(utc_start, ext='log', daily=True))
|
||||
timelog_file.touch(exist_ok=True)
|
||||
with timelog_file.open('a') as timelog:
|
||||
timelog.write(text + '\n')
|
||||
if end_section:
|
||||
timelog.write('\n\n')
|
||||
|
||||
|
||||
def record_task(whatnext, whatdid, start, end=None):
|
||||
""" Record completed pomodoro to CSV
|
||||
"""
|
||||
if end is None:
|
||||
end = datetime.now(pytz.utc)
|
||||
with open(prepare_file(), 'a', newline='') as csvfile:
|
||||
# TODO make first line started, recorded, description, intention
|
||||
|
||||
filepath = prepare_file(start)
|
||||
if not os.path.isfile(filepath):
|
||||
with open(filepath, 'w', newline='') as csvfile:
|
||||
log = csv.writer(csvfile)
|
||||
log.writewrow(['started', 'recorded', 'description', 'intention'])
|
||||
|
||||
with open(filepath, 'a', newline='') as csvfile:
|
||||
timewriter = csv.writer(csvfile)
|
||||
timewriter.writerow([start, end, whatdid, whatnext])
|
||||
|
||||
|
@ -84,7 +90,7 @@ def countdown_to(until):
|
|||
print('\r', str_minutes(to_go), sep='', end='')
|
||||
time.sleep(1)
|
||||
|
||||
def prepare_file(ext='csv', daily=False, utc_start):
|
||||
def prepare_file(utc_start, ext='csv', daily=False):
|
||||
# Ensure log directory exists.
|
||||
if not os.path.exists('log'):
|
||||
os.makedirs('log')
|
||||
|
@ -148,6 +154,5 @@ def main():
|
|||
record_task(whatnext, 'Incomplete, interrupted task:' + whatnext, start)
|
||||
log_step('Incomplete, interrupted task:' + whatnext, start, True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue