From 98924e362e05357d47e2bef2ef09e5c8eff1a91c Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Tue, 15 Oct 2024 14:35:19 -0400 Subject: [PATCH] [tasks] Fix loading todoist data from webhook data --- vrobbler/apps/scrobbles/scrobblers.py | 4 ++-- vrobbler/apps/tasks/webhooks.py | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/vrobbler/apps/scrobbles/scrobblers.py b/vrobbler/apps/scrobbles/scrobblers.py index 83db317..21dfc4b 100644 --- a/vrobbler/apps/scrobbles/scrobblers.py +++ b/vrobbler/apps/scrobbles/scrobblers.py @@ -312,8 +312,8 @@ def manual_scrobble_from_url(url: str, user_id: int) -> Scrobble: def todoist_scrobble_task_finish(todoist_task: dict, user_id: int) -> Scrobble: scrobble = Scrobble.objects.filter( - user_id=user_id, logdata__todoist_id=todoist_task.get("todoist_id") - ) + user_id=user_id, log__todoist_id=todoist_task.get("todoist_id") + ).first() if not scrobble.in_progress or scrobble.played_to_completion: logger.warning( diff --git a/vrobbler/apps/tasks/webhooks.py b/vrobbler/apps/tasks/webhooks.py index 18fa9bb..b0fcdb2 100644 --- a/vrobbler/apps/tasks/webhooks.py +++ b/vrobbler/apps/tasks/webhooks.py @@ -23,19 +23,17 @@ def todoist_webhook(request): "[todoist_webhook] called", extra={"post_data": post_data}, ) - # ["inprogress","project","work"], - # :item:updated, todoist_type, todoist_event = post_data.get("event_name").split(":") + event_data = post_data.get("event_data", {}) todoist_task = { - "todoist_id": post_data.get("id"), - "todoist_label_list": post_data.get("event_data", {}).get("labels"), + "todoist_id": event_data.get("id"), + "todoist_label_list": event_data.get("labels"), "todoist_type": todoist_type, "todoist_event": todoist_event, - "title": post_data.get("content"), - "description": post_data.get("description"), - "timestamp_utc": pendulum.parse( - post_data.get("event_data", {}).get("updated_at") - ), + "todoist_project_id": event_data.get("project_id"), + "description": event_data.get("content"), + "details": event_data.get("description"), + "timestamp_utc": pendulum.parse(event_data.get("updated_at")), } if todoist_task["todoist_type"] != "item" or todoist_task[