[boardgames] Start adding email scrobbling for board games

This commit is contained in:
2025-07-02 10:55:24 -04:00
parent a2f64a98c3
commit 0fa831fa42
4 changed files with 173 additions and 4 deletions

View File

@ -1,7 +1,7 @@
import logging
import re
from datetime import datetime
from typing import Optional
from typing import Any, Optional
import pendulum
import pytz
@ -285,7 +285,7 @@ def manual_scrobble_book(
def manual_scrobble_board_game(
bggeek_id: str, user_id: int, action: Optional[str] = None
):
) -> Scrobble | None:
boardgame = BoardGame.find_or_create(bggeek_id)
if not boardgame:
@ -311,6 +311,28 @@ def manual_scrobble_board_game(
return Scrobble.create_or_update(boardgame, user_id, scrobble_dict)
def email_scrobble_board_game(
bgstat_data: dict[str, Any], user_id: int
) -> Scrobble | None:
game_dict: dict[str, Any] = bgstat_data.get("games", [])[0]
if not game_dict.get("bggId", False):
logger.info(
"Data from BG Stats JSON had not BGG ID, not scrobbling",
extra={"bgstat_data": bgstat_data},
)
return
boardgame = BoardGame.find_or_create(game_dict.get("bggId"))
# TODO Enrich data from our bgstats data?
#
# TODO Build up board game meta data from the rest of the data
scrobble_dict = {}
players_list: list[dict[str, Any]] = bgstat_data.get("players", [])
location: dict[str, Any] = bgstat_data.get("locations", [])[0]
return Scrobble.create_or_update(boardgame, user_id, scrobble_dict)
def manual_scrobble_from_url(
url: str, user_id: int, action: Optional[str] = None
) -> Scrobble:
@ -411,7 +433,9 @@ def todoist_scrobble_task(
stopped: bool = False,
user_context_list: list[str] = [],
) -> Scrobble:
title = get_title_from_labels(todoist_task.get("todoist_label_list", []), user_context_list)
title = get_title_from_labels(
todoist_task.get("todoist_label_list", []), user_context_list
)
task = Task.find_or_create(title)
timestamp = pendulum.parse(todoist_task.get("updated_at", timezone.now()))
@ -536,7 +560,9 @@ def emacs_scrobble_task(
user_context_list: list[str] = [],
) -> Scrobble | None:
source_id = task_data.get("source_id")
title = get_title_from_labels(task_data.get("labels", []), user_context_list)
title = get_title_from_labels(
task_data.get("labels", []), user_context_list
)
task = Task.find_or_create(title)