diff --git a/bin/work b/bin/work index cf7a844..c1f76f8 100755 --- a/bin/work +++ b/bin/work @@ -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")