diff --git a/vrobbler/apps/boardgames/bgg.py b/vrobbler/apps/boardgames/bgg.py index 10baea4..a69ac02 100644 --- a/vrobbler/apps/boardgames/bgg.py +++ b/vrobbler/apps/boardgames/bgg.py @@ -1,8 +1,11 @@ +import logging from typing import Optional import requests from bs4 import BeautifulSoup +logger = logging.getLogger(__name__) + SEARCH_ID_URL = ( "https://boardgamegeek.com/xmlapi/search?search={query}&exact=1" ) @@ -51,11 +54,14 @@ def lookup_boardgame_from_bgg(lookup_id: str) -> dict: try: bgg_id = int(lookup_id) + logger.debug(f"Using BGG ID {bgg_id} to find board game") except ValueError: title = lookup_id + logger.debug(f"Using title {title} to find board game") if not bgg_id: bgg_id = lookup_boardgame_id_from_bgg(title) + url = GAME_ID_URL.format(id=bgg_id) r = requests.get(url, headers=headers) if r.status_code == 200: @@ -68,6 +74,7 @@ def lookup_boardgame_from_bgg(lookup_id: str) -> dict: seconds_to_play = int(minutes) * 60 game_dict = { + "bggeek_id": bgg_id, "title": take_first(soup.findAll("name", primary="true")), "description": take_first(soup.findAll("description")), "year_published": take_first(soup.findAll("yearpublished")), diff --git a/vrobbler/apps/boardgames/models.py b/vrobbler/apps/boardgames/models.py index 5625bde..f90ff98 100644 --- a/vrobbler/apps/boardgames/models.py +++ b/vrobbler/apps/boardgames/models.py @@ -11,6 +11,7 @@ from django.db import models from django.urls import reverse from django_extensions.db.models import TimeStampedModel from scrobbles.mixins import ScrobblableMixin +from vrobbler.apps.boardgames.bgg import lookup_boardgame_id_from_bgg logger = logging.getLogger(__name__) BNULL = {"blank": True, "null": True} @@ -83,10 +84,10 @@ class BoardGame(ScrobblableMixin): def fix_metadata(self, data: dict = {}, force_update=False) -> None: - if not self.bggeek_id or force_update: + if not self.published_date or force_update: if not data: - data = get_game_by_id_from_bgg(self.bggeek_id) + data = lookup_boardgame_from_bgg(str(self.bggeek_id)) cover_url = data.pop("cover_url") year = data.pop("year_published") diff --git a/vrobbler/apps/scrobbles/scrobblers.py b/vrobbler/apps/scrobbles/scrobblers.py index c162478..92eda6a 100644 --- a/vrobbler/apps/scrobbles/scrobblers.py +++ b/vrobbler/apps/scrobbles/scrobblers.py @@ -228,6 +228,10 @@ def manual_scrobble_book(openlibrary_id: str, user_id: int): def manual_scrobble_board_game(bggeek_id: str, user_id: int): boardgame = BoardGame.find_or_create(bggeek_id) + if not boardgame: + logger.error(f"No board game found for ID {bggeek_id}") + return + scrobble_dict = { "user_id": user_id, "timestamp": timezone.now(), diff --git a/vrobbler/templates/boardgames/boardgame_detail.html b/vrobbler/templates/boardgames/boardgame_detail.html index fccdbe1..32a536e 100644 --- a/vrobbler/templates/boardgames/boardgame_detail.html +++ b/vrobbler/templates/boardgames/boardgame_detail.html @@ -43,7 +43,6 @@

{{object.scrobble_set.count}} scrobbles

-

{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete %} and completed{% else %} spent playing{% endif %}

{% if object.scrobble_set.last.long_play_complete == True %} Play again @@ -60,18 +59,14 @@ Date - Completed - Duration - Platforms + Publisher {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} {{scrobble.timestamp}} - {% if scrobble.long_play_complete == True %}Yes{% endif %} - {% if scrobble.in_progress %}Now playing{% else %}{{scrobble.playback_position_seconds|natural_duration}}{% endif %} - {% for platform in scrobble.video_game.platforms.all %}{{platform}}{% if not forloop.last %}, {% endif %}{% endfor %} + {{scrobble.media_obj.publisher}} {% endfor %} diff --git a/vrobbler/templates/videogames/videogame_detail.html b/vrobbler/templates/videogames/videogame_detail.html index d15db67..bef128f 100644 --- a/vrobbler/templates/videogames/videogame_detail.html +++ b/vrobbler/templates/videogames/videogame_detail.html @@ -45,7 +45,9 @@

{{object.scrobble_set.count}} scrobbles

+ {% if object.scrobble_set.last.long_play_seconds %}

{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete %} and completed{% else %} spent playing{% endif %}

+ {% endif %}

{% if object.scrobble_set.last.long_play_complete == True %} Play again