From de6e9ce2d69dd0bca77f456b54684aa03b02d59a Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Tue, 15 Oct 2024 15:23:15 -0400 Subject: [PATCH] [tasks] We only care about in-progress for scrobbling --- vrobbler/apps/scrobbles/scrobblers.py | 11 ++++++++--- vrobbler/apps/tasks/webhooks.py | 5 +---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/vrobbler/apps/scrobbles/scrobblers.py b/vrobbler/apps/scrobbles/scrobblers.py index 39d743a..4099947 100644 --- a/vrobbler/apps/scrobbles/scrobblers.py +++ b/vrobbler/apps/scrobbles/scrobblers.py @@ -353,6 +353,14 @@ def todoist_scrobble_task(todoist_task: dict, user_id: int) -> Scrobble: title = " ".join([prefix.capitalize(), suffix.capitalize()]) task = Task.find_or_create(title) + + # is_complete = "completed" in todoist_task["todoist_event"] + is_no_longer_in_progress = ( + "inprogress" not in todoist_task["todoist_label_list"] + ) + if is_no_longer_in_progress: + scrobble = todoist_scrobble_task_finish(todoist_task, user_id) + in_progress_scrobble = Scrobble.objects.filter( in_progress=True, log__todoist_id=todoist_task.get("todoist_id"), @@ -361,9 +369,6 @@ def todoist_scrobble_task(todoist_task: dict, user_id: int) -> Scrobble: if in_progress_scrobble: return in_progress_scrobble - if "inprogress" not in todoist_task["todoist_label_list"]: - return todoist_scrobble_task_finish(todoist_task, user_id) - # TODO Should use updated_at from TOdoist, but parsing isn't working scrobble_dict = { "user_id": user_id, diff --git a/vrobbler/apps/tasks/webhooks.py b/vrobbler/apps/tasks/webhooks.py index 8e7473c..6099477 100644 --- a/vrobbler/apps/tasks/webhooks.py +++ b/vrobbler/apps/tasks/webhooks.py @@ -60,10 +60,7 @@ def todoist_webhook(request): if not user_id: user_id = 1 - if "completed" in todoist_task["todoist_event"]: - scrobble = todoist_scrobble_task_finish(todoist_task, user_id) - else: - scrobble = todoist_scrobble_task(todoist_task, user_id) + scrobble = todoist_scrobble_task(todoist_task, user_id) if not scrobble: return Response(