|
@@ -1,7 +1,7 @@
|
|
import logging
|
|
import logging
|
|
import re
|
|
import re
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
-from typing import Optional
|
|
|
|
|
|
+from typing import Any, Optional
|
|
|
|
|
|
import pendulum
|
|
import pendulum
|
|
import pytz
|
|
import pytz
|
|
@@ -285,7 +285,7 @@ def manual_scrobble_book(
|
|
|
|
|
|
def manual_scrobble_board_game(
|
|
def manual_scrobble_board_game(
|
|
bggeek_id: str, user_id: int, action: Optional[str] = None
|
|
bggeek_id: str, user_id: int, action: Optional[str] = None
|
|
-):
|
|
|
|
|
|
+) -> Scrobble | None:
|
|
boardgame = BoardGame.find_or_create(bggeek_id)
|
|
boardgame = BoardGame.find_or_create(bggeek_id)
|
|
|
|
|
|
if not boardgame:
|
|
if not boardgame:
|
|
@@ -311,6 +311,28 @@ def manual_scrobble_board_game(
|
|
return Scrobble.create_or_update(boardgame, user_id, scrobble_dict)
|
|
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(
|
|
def manual_scrobble_from_url(
|
|
url: str, user_id: int, action: Optional[str] = None
|
|
url: str, user_id: int, action: Optional[str] = None
|
|
) -> Scrobble:
|
|
) -> Scrobble:
|
|
@@ -411,7 +433,9 @@ def todoist_scrobble_task(
|
|
stopped: bool = False,
|
|
stopped: bool = False,
|
|
user_context_list: list[str] = [],
|
|
user_context_list: list[str] = [],
|
|
) -> Scrobble:
|
|
) -> 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)
|
|
task = Task.find_or_create(title)
|
|
|
|
|
|
timestamp = pendulum.parse(todoist_task.get("updated_at", timezone.now()))
|
|
timestamp = pendulum.parse(todoist_task.get("updated_at", timezone.now()))
|
|
@@ -536,7 +560,9 @@ def emacs_scrobble_task(
|
|
user_context_list: list[str] = [],
|
|
user_context_list: list[str] = [],
|
|
) -> Scrobble | None:
|
|
) -> Scrobble | None:
|
|
source_id = task_data.get("source_id")
|
|
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)
|
|
task = Task.find_or_create(title)
|
|
|
|
|