another bug fix

This commit is contained in:
bain 2022-08-28 01:18:07 +02:00
parent 4e39127952
commit 00bcc828f4
No known key found for this signature in database
GPG key ID: A708F07AF3D92C02

View file

@ -98,6 +98,13 @@ def get_toggl_entries(
) )
projects = {p["id"]: p["name"] for p in resp.json()} 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 = [] entries = []
resp = requests.get( resp = requests.get(
f"https://api.track.toggl.com/api/v9/me/time_entries", f"https://api.track.toggl.com/api/v9/me/time_entries",
@ -111,9 +118,7 @@ def get_toggl_entries(
entries = resp.json() entries = resp.json()
last_entry = next( last_entry = next(
filter( filter(
lambda x: x["duration"] > 0 valid_entry,
and entry["server_deleted_at"] is None
and entry["project_id"] in projects,
entries, entries,
), ),
None, None,
@ -122,11 +127,7 @@ def get_toggl_entries(
# construct a dict of d["project name"] = [[date, description, duration (hours), wage], ...] # construct a dict of d["project name"] = [[date, description, duration (hours), wage], ...]
out = defaultdict(list) out = defaultdict(list)
for entry in reversed(entries): for entry in reversed(entries):
if ( if not valid_entry(entry):
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
):
continue continue
start = datetime.datetime.fromisoformat(entry["start"].replace("Z", "+00:00")) start = datetime.datetime.fromisoformat(entry["start"].replace("Z", "+00:00"))
end = datetime.datetime.fromisoformat(entry["stop"].replace("Z", "+00:00")) end = datetime.datetime.fromisoformat(entry["stop"].replace("Z", "+00:00"))