From 00bcc828f43718760bedb712dec86050f1011dfb Mon Sep 17 00:00:00 2001 From: bain Date: Sun, 28 Aug 2022 01:18:07 +0200 Subject: [PATCH] another bug fix --- toggl2sheets.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/toggl2sheets.py b/toggl2sheets.py index 937e000..04c7ec3 100644 --- a/toggl2sheets.py +++ b/toggl2sheets.py @@ -98,6 +98,13 @@ def get_toggl_entries( ) projects = {p["id"]: p["name"] for p in resp.json()} + def valid_entry(e): + return ( + e["duration"] > 0 + and e["server_deleted_at"] is None + and e["project_id"] in projects + ) + entries = [] resp = requests.get( f"https://api.track.toggl.com/api/v9/me/time_entries", @@ -111,9 +118,7 @@ def get_toggl_entries( entries = resp.json() last_entry = next( filter( - lambda x: x["duration"] > 0 - and entry["server_deleted_at"] is None - and entry["project_id"] in projects, + valid_entry, entries, ), None, @@ -122,11 +127,7 @@ def get_toggl_entries( # construct a dict of d["project name"] = [[date, description, duration (hours), wage], ...] out = defaultdict(list) for entry in reversed(entries): - if ( - entry["duration"] <= 0 # running entry - or entry["server_deleted_at"] is not None # deleted entry - or entry["project_id"] not in projects # entry not from selected workspace - ): + if not valid_entry(entry): continue start = datetime.datetime.fromisoformat(entry["start"].replace("Z", "+00:00")) end = datetime.datetime.fromisoformat(entry["stop"].replace("Z", "+00:00"))