From 34a6ac192d1d3b65cab3adcdf3bccb0e1f5e6c66 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 12 Mar 2023 16:15:20 -0400 Subject: [PATCH] Fix progress for books with no scrobbles --- vrobbler/apps/books/models.py | 5 ++++- vrobbler/apps/books/openlibrary.py | 4 ---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/vrobbler/apps/books/models.py b/vrobbler/apps/books/models.py index cc13974..d7deb31 100644 --- a/vrobbler/apps/books/models.py +++ b/vrobbler/apps/books/models.py @@ -160,7 +160,10 @@ class Book(LongPlayScrobblableMixin): """Used to keep track of whether the book is complete or not""" user = User.objects.get(id=user_id) last_scrobble = get_scrobbles_for_media(self, user).last() - return int((last_scrobble.book_pages_read / self.pages) * 100) + progress = 0 + if last_scrobble: + progress = int((last_scrobble.book_pages_read / self.pages) * 100) + return progress @classmethod def find_or_create(cls, data_dict: dict) -> "Game": diff --git a/vrobbler/apps/books/openlibrary.py b/vrobbler/apps/books/openlibrary.py index 931d25d..96dc776 100644 --- a/vrobbler/apps/books/openlibrary.py +++ b/vrobbler/apps/books/openlibrary.py @@ -72,10 +72,6 @@ def lookup_book_from_openlibrary(title: str, author: str = None) -> dict: return {} top = results.get("docs")[0] - if author and author not in top["author_name"]: - logger.warn( - f"Lookup for {title} found top result with mismatched author" - ) ol_id = top.get("cover_edition_key") ol_author_id = get_first("author_key", top) first_sentence = ""