Clean up board game scrobbling
This commit is contained in:
@ -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")),
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -43,7 +43,6 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<p>{{object.scrobble_set.count}} scrobbles</p>
|
||||
<p>{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete %} and completed{% else %} spent playing{% endif %}</p>
|
||||
<p>
|
||||
{% if object.scrobble_set.last.long_play_complete == True %}
|
||||
<a href="">Play again</a>
|
||||
@ -60,18 +59,14 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Date</th>
|
||||
<th scope="col">Completed</th>
|
||||
<th scope="col">Duration</th>
|
||||
<th scope="col">Platforms</th>
|
||||
<th scope="col">Publisher</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
|
||||
<tr>
|
||||
<td>{{scrobble.timestamp}}</td>
|
||||
<td>{% if scrobble.long_play_complete == True %}Yes{% endif %}</td>
|
||||
<td>{% if scrobble.in_progress %}Now playing{% else %}{{scrobble.playback_position_seconds|natural_duration}}{% endif %}</td>
|
||||
<td>{% for platform in scrobble.video_game.platforms.all %}<a href="{{platform.get_absolute_url}}">{{platform}}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</td>
|
||||
<td>{{scrobble.media_obj.publisher}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
@ -45,7 +45,9 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<p>{{object.scrobble_set.count}} scrobbles</p>
|
||||
{% if object.scrobble_set.last.long_play_seconds %}
|
||||
<p>{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete %} and completed{% else %} spent playing{% endif %}</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
{% if object.scrobble_set.last.long_play_complete == True %}
|
||||
<a href="">Play again</a>
|
||||
|
||||
Reference in New Issue
Block a user