[work] small fixes

This commit is contained in:
Lara 2020-02-28 17:37:00 -05:00
parent d9b0a0fbab
commit 6ced297495

View file

@ -52,7 +52,11 @@ def td_format(td):
def get_today_fields():
try:
with open(TODAY_FILE, "r") as f:
line_count = 0
for line in f:
line_count += 1
if line_count > 1:
log("Warning: incomplete day leftover in {}".format(TODAY_FILE))
if line.startswith(start_time.strftime("%Y-%m-%d")):
return line.strip().split(",")
except FileNotFoundError:
@ -131,7 +135,7 @@ def work_start(args):
hour = start_time.strftime("%H:%M")
if fields:
die("You already started working")
with open(TODAY_FILE, "w") as f:
with open(TODAY_FILE, "a") as f:
f.write("{},{}".format(
start_time.strftime("%Y-%m-%d"), hour))
log("Started working at {}".format(hour))
@ -205,7 +209,8 @@ def work_parse(args):
for line in f:
fields = line.split(",")
if len(fields) < 6:
break
log("Record: '{}' hasn't got enough fields ({})".format(line, len(fields)))
continue
morning = datetime.strptime(fields[1], "%H:%M")
break_start = datetime.strptime(fields[2], "%H:%M")
break_end = datetime.strptime(fields[3], "%H:%M")