mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 21:11:16 +00:00
Fixes bugs in openlibrary connector
This commit is contained in:
parent
4765f965cf
commit
1cdd7ea1fc
1 changed files with 6 additions and 5 deletions
|
@ -45,7 +45,7 @@ class OpenLibraryConnector(AbstractConnector):
|
||||||
raise ValueError('Invalid OpenLibrary ID')
|
raise ValueError('Invalid OpenLibrary ID')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
book = models.Book.objects.get(openlibrary_key=olkey)
|
book = model.objects.get(openlibrary_key=olkey)
|
||||||
return book
|
return book
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
# no book was found, so we start creating a new one
|
# no book was found, so we start creating a new one
|
||||||
|
@ -68,16 +68,17 @@ class OpenLibraryConnector(AbstractConnector):
|
||||||
book.pages = data.get('pages')
|
book.pages = data.get('pages')
|
||||||
#book.published_date = data.get('publish_date')
|
#book.published_date = data.get('publish_date')
|
||||||
|
|
||||||
|
book.save()
|
||||||
|
|
||||||
# this book sure as heck better be an edition
|
# this book sure as heck better be an edition
|
||||||
if data.get('works'):
|
if data.get('works'):
|
||||||
key = data.get('works')[0]['key']
|
key = data.get('works')[0]['key']
|
||||||
key = key.split('/')[-1]
|
key = key.split('/')[-1]
|
||||||
work = self.get_or_create_book(key)
|
work = self.get_or_create_book(key)
|
||||||
book.parent_work = work
|
book.parent_work = work
|
||||||
book.save()
|
|
||||||
|
|
||||||
# we also need to know the author get the cover
|
# we also need to know the author get the cover
|
||||||
for author_blob in data.get('authors'):
|
for author_blob in data.get('authors', []):
|
||||||
# this id is "/authors/OL1234567A" and we want just "OL1234567A"
|
# this id is "/authors/OL1234567A" and we want just "OL1234567A"
|
||||||
author_blob = author_blob.get('author', author_blob)
|
author_blob = author_blob.get('author', author_blob)
|
||||||
author_id = author_blob['key']
|
author_id = author_blob['key']
|
||||||
|
@ -95,7 +96,7 @@ class OpenLibraryConnector(AbstractConnector):
|
||||||
if not re.match(r'^OL\d+A$', olkey):
|
if not re.match(r'^OL\d+A$', olkey):
|
||||||
raise ValueError('Invalid OpenLibrary author ID')
|
raise ValueError('Invalid OpenLibrary author ID')
|
||||||
try:
|
try:
|
||||||
author = models.Author.objects.get(openlibrary_key=olkey)
|
return models.Author.objects.get(openlibrary_key=olkey)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ class OpenLibraryConnector(AbstractConnector):
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
image_content = ContentFile(requests.get(url).content)
|
image_content = ContentFile(response.content)
|
||||||
return [image_name, image_content]
|
return [image_name, image_content]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue