forked from mirrors/bookwyrm
Save source_url in connectors
This commit is contained in:
parent
54b5f0097b
commit
16fec1b6d5
3 changed files with 6 additions and 11 deletions
|
@ -20,8 +20,6 @@ def get_book(book):
|
||||||
'misc_identifiers',
|
'misc_identifiers',
|
||||||
|
|
||||||
'source_url',
|
'source_url',
|
||||||
'sync',
|
|
||||||
'last_sync_date',
|
|
||||||
|
|
||||||
'description',
|
'description',
|
||||||
'language',
|
'language',
|
||||||
|
|
|
@ -54,21 +54,17 @@ class Connector(AbstractConnector):
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
# great, we can update our book.
|
# great, we can update our book.
|
||||||
noop = lambda x: x
|
mappings = {
|
||||||
formatters = {
|
'published_date': ('published_date', get_date),
|
||||||
'published_date': get_date,
|
'first_published_date': ('first_published_date', get_date),
|
||||||
'first_published_date': get_date,
|
|
||||||
}
|
}
|
||||||
for (key, value) in data.items():
|
book = update_from_mappings(book, data, mappings)
|
||||||
formatter = formatters[key] if key in formatters else noop
|
|
||||||
|
|
||||||
if self.has_attr(book, key):
|
book.source_url = response.url
|
||||||
book.__setattr__(key, formatter(value))
|
|
||||||
book.save()
|
book.save()
|
||||||
|
|
||||||
if data.get('parent_work'):
|
if data.get('parent_work'):
|
||||||
work = self.get_or_create_book(data.get('parent_work'))
|
work = self.get_or_create_book(data.get('parent_work'))
|
||||||
|
|
||||||
book.parent_work = work
|
book.parent_work = work
|
||||||
|
|
||||||
for author_blob in data.get('authors', []):
|
for author_blob in data.get('authors', []):
|
||||||
|
|
|
@ -81,6 +81,7 @@ class Connector(AbstractConnector):
|
||||||
if 'goodreads' in data['identifiers']:
|
if 'goodreads' in data['identifiers']:
|
||||||
book.goodreads_key = data['identifiers']['goodreads']
|
book.goodreads_key = data['identifiers']['goodreads']
|
||||||
|
|
||||||
|
book.source_url = response.url
|
||||||
book.save()
|
book.save()
|
||||||
|
|
||||||
# this book sure as heck better be an edition
|
# this book sure as heck better be an edition
|
||||||
|
|
Loading…
Reference in a new issue