[scrobbles] Start cleaning up logdata

This commit is contained in:
2025-08-05 02:01:31 -04:00
parent 06e075553a
commit 278cab32ea
9 changed files with 191 additions and 54 deletions

View File

@ -411,7 +411,7 @@ def email_scrobble_board_game(
except IndexError:
second = 0
log_data["details"] = play_dict.get("comments")
log_data["notes"] = [play_dict.get("comments")]
log_data["expansion_ids"] = []
try:
base_game = base_games[play_dict.get("gameRefId")]
@ -587,9 +587,9 @@ def todoist_scrobble_update_task(
)
return
existing_notes = scrobble.log.get("notes", {})
existing_notes[todoist_note.get("todoist_id")] = todoist_note.get("notes")
scrobble.log["notes"] = existing_notes
if not scrobble.log.get("notes"):
scrobble.log["notes"] = []
scrobble.log["notes"].append(todoist_note.get("notes"))
scrobble.save(update_fields=["log"])
logger.info(
"[todoist_scrobble_update_task] todoist note added",
@ -615,7 +615,7 @@ def todoist_scrobble_task(
)
task = Task.find_or_create(title)
timestamp = pendulum.parse(todoist_task.get("updated_at", timezone.now()))
timestamp = pendulum.parse(todoist_task.pop("updated_at", timezone.now()))
in_progress_scrobble = Scrobble.objects.filter(
user_id=user_id,
in_progress=True,
@ -657,8 +657,12 @@ def todoist_scrobble_task(
)
return todoist_scrobble_task_finish(todoist_task, user_id, timestamp)
# Default to create new scrobble "if not in_progress_scrobble and in_progress_in_todoist"
# TODO Should use updated_at from TOdoist, but parsing isn't working
todoist_task["title"] = todoist_task.pop("description")
todoist_task["description"] = todoist_task.pop("details")
todoist_task["labels"] = todoist_task.pop("todoist_label_list", [])
todoist_task.pop("todoist_type")
todoist_task.pop("todoist_event")
scrobble_dict = {
"user_id": user_id,
"timestamp": timestamp,
@ -686,8 +690,8 @@ def emacs_scrobble_update_task(
scrobble = Scrobble.objects.filter(
in_progress=True,
user_id=user_id,
log__source_id=emacs_id,
log__source="orgmode",
log__orgmode_id=emacs_id,
source="Org-mode",
).first()
if not scrobble:
@ -736,18 +740,18 @@ def emacs_scrobble_task(
stopped: bool = False,
user_context_list: list[str] = [],
) -> Scrobble | None:
source_id = task_data.get("source_id")
orgmode_id = task_data.get("source_id")
title = get_title_from_labels(
task_data.get("labels", []), user_context_list
)
task = Task.find_or_create(title)
timestamp = pendulum.parse(task_data.get("updated_at", timezone.now()))
timestamp = pendulum.parse(task_data.pop("updated_at", timezone.now()))
in_progress_scrobble = Scrobble.objects.filter(
user_id=user_id,
in_progress=True,
log__source_id=source_id,
log__orgmode_id=orgmode_id,
log__source="orgmode",
task=task,
).last()
@ -756,7 +760,7 @@ def emacs_scrobble_task(
logger.info(
"[emacs_scrobble_task] cannot stop already stopped task",
extra={
"emacs_id": source_id,
"orgmode_id": orgmode_id,
},
)
return
@ -765,7 +769,7 @@ def emacs_scrobble_task(
logger.info(
"[emacs_scrobble_task] cannot start already started task",
extra={
"emacs_id": source_id,
"ormode_id": orgmode_id,
},
)
return in_progress_scrobble
@ -775,7 +779,7 @@ def emacs_scrobble_task(
logger.info(
"[emacs_scrobble_task] finishing",
extra={
"emacs_id": source_id,
"orgmode_id": orgmode_id,
},
)
in_progress_scrobble.stop(timestamp=timestamp, force_finish=True)
@ -786,11 +790,17 @@ def emacs_scrobble_task(
notes = task_data.pop("notes")
if notes:
task_data["notes"] = []
for note in notes:
task_data["notes"].append(
{note.get("timestamp"): note.get("content")}
)
task_data["notes"] = [note.get("content") for note in notes]
task_data["title"] = task_data.pop("description")
task_data["description"] = task_data.pop("body")
task_data["labels"] = task_data.pop("labels")
task_data["orgmode_id"] = task_data.pop("source_id")
task_data["orgmode_state"] = task_data.pop("state")
task_data["orgmode_properties"] = task_data.pop("properties")
task_data["orgmode_drawers"] = task_data.pop("drawers")
task_data["orgmode_timestamps"] = task_data.pop("timestamps")
task_data.pop("source")
scrobble_dict = {
"user_id": user_id,