Merge branch 'main' into inventaire

This commit is contained in:
Mouse Reeve
2021-04-26 14:22:05 -07:00
280 changed files with 20693 additions and 9991 deletions

View File

@ -9,7 +9,7 @@ from .openlibrary_languages import languages
class Connector(AbstractConnector):
""" instantiate a connector for OL """
"""instantiate a connector for OL"""
def __init__(self, identifier):
super().__init__(identifier)
@ -59,7 +59,7 @@ class Connector(AbstractConnector):
]
def get_remote_id_from_data(self, data):
""" format a url from an openlibrary id field """
"""format a url from an openlibrary id field"""
try:
key = data["key"]
except KeyError:
@ -87,16 +87,19 @@ class Connector(AbstractConnector):
return get_data(url)
def get_authors_from_data(self, data):
""" parse author json and load or create authors """
"""parse author json and load or create authors"""
for author_blob in data.get("authors", []):
author_blob = author_blob.get("author", author_blob)
# this id is "/authors/OL1234567A"
author_id = author_blob["key"]
url = "%s%s" % (self.base_url, author_id)
yield self.get_or_create_author(url)
author = self.get_or_create_author(url)
if not author:
continue
yield author
def get_cover_url(self, cover_blob, size="L"):
""" ask openlibrary for the cover """
"""ask openlibrary for the cover"""
if not cover_blob:
return None
cover_id = cover_blob[0]
@ -138,7 +141,7 @@ class Connector(AbstractConnector):
)
def load_edition_data(self, olkey):
""" query openlibrary for editions of a work """
"""query openlibrary for editions of a work"""
url = "%s/works/%s/editions" % (self.books_url, olkey)
return get_data(url)
@ -163,7 +166,7 @@ class Connector(AbstractConnector):
def ignore_edition(edition_data):
""" don't load a million editions that have no metadata """
"""don't load a million editions that have no metadata"""
# an isbn, we love to see it
if edition_data.get("isbn_13") or edition_data.get("isbn_10"):
return False
@ -182,19 +185,19 @@ def ignore_edition(edition_data):
def get_description(description_blob):
""" descriptions can be a string or a dict """
"""descriptions can be a string or a dict"""
if isinstance(description_blob, dict):
return description_blob.get("value")
return description_blob
def get_openlibrary_key(key):
""" convert /books/OL27320736M into OL27320736M """
"""convert /books/OL27320736M into OL27320736M"""
return key.split("/")[-1]
def get_languages(language_blob):
""" /language/eng -> English """
"""/language/eng -> English"""
langs = []
for lang in language_blob:
langs.append(languages.get(lang.get("key", ""), None))
@ -202,7 +205,7 @@ def get_languages(language_blob):
def pick_default_edition(options):
""" favor physical copies with covers in english """
"""favor physical copies with covers in english"""
if not options:
return None
if len(options) == 1: