From 16fec1b6d5355e0c5ad2d0b23446c4c2375877b9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 28 Mar 2020 13:14:06 -0700 Subject: [PATCH] Save source_url in connectors --- fedireads/activitypub/book.py | 2 -- fedireads/connectors/fedireads_connector.py | 14 +++++--------- fedireads/connectors/openlibrary.py | 1 + 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/fedireads/activitypub/book.py b/fedireads/activitypub/book.py index d3ee015e..8d6c6993 100644 --- a/fedireads/activitypub/book.py +++ b/fedireads/activitypub/book.py @@ -20,8 +20,6 @@ def get_book(book): 'misc_identifiers', 'source_url', - 'sync', - 'last_sync_date', 'description', 'language', diff --git a/fedireads/connectors/fedireads_connector.py b/fedireads/connectors/fedireads_connector.py index c3956c05..dc838754 100644 --- a/fedireads/connectors/fedireads_connector.py +++ b/fedireads/connectors/fedireads_connector.py @@ -54,21 +54,17 @@ class Connector(AbstractConnector): data = response.json() # great, we can update our book. - noop = lambda x: x - formatters = { - 'published_date': get_date, - 'first_published_date': get_date, + mappings = { + 'published_date': ('published_date', get_date), + 'first_published_date': ('first_published_date', get_date), } - for (key, value) in data.items(): - formatter = formatters[key] if key in formatters else noop + book = update_from_mappings(book, data, mappings) - if self.has_attr(book, key): - book.__setattr__(key, formatter(value)) + book.source_url = response.url book.save() if data.get('parent_work'): work = self.get_or_create_book(data.get('parent_work')) - book.parent_work = work for author_blob in data.get('authors', []): diff --git a/fedireads/connectors/openlibrary.py b/fedireads/connectors/openlibrary.py index 7270d7bb..184d59aa 100644 --- a/fedireads/connectors/openlibrary.py +++ b/fedireads/connectors/openlibrary.py @@ -81,6 +81,7 @@ class Connector(AbstractConnector): if 'goodreads' in data['identifiers']: book.goodreads_key = data['identifiers']['goodreads'] + book.source_url = response.url book.save() # this book sure as heck better be an edition