toggl2sheets

toggl entries to google sheets
git clone git://git.bain.cz/toggl2sheets.git
Log | Files | Refs | README

commit 00bcc828f43718760bedb712dec86050f1011dfb
parent 4e3912795262f6f2ac24d93cf2cd3ac8f3c46ed2
Author: bain <bain@bain.cz>
Date:   Sun, 28 Aug 2022 01:18:07 +0200

another bug fix

Diffstat:
Mtoggl2sheets.py | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git 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"))