another bug fix
This commit is contained in:
parent
4e39127952
commit
00bcc828f4
1 changed files with 9 additions and 8 deletions
|
@ -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"))
|
||||||
|
|
Loading…
Reference in a new issue