diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 378f23f7..8007bb1a 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -44,7 +44,7 @@ class AbstractMinimalConnector(ABC): if min_confidence: params["min_confidence"] = min_confidence - data = get_data( + data = self.get_search_data( "%s%s" % (self.search_url, query), params=params, ) @@ -57,7 +57,7 @@ class AbstractMinimalConnector(ABC): def isbn_search(self, query): """ isbn search """ params = {} - data = get_data( + data = self.get_search_data( "%s%s" % (self.isbn_search_url, query), params=params, ) @@ -117,7 +117,7 @@ class AbstractConnector(AbstractMinimalConnector): return existing # load the json - data = get_data(remote_id) + data = self.get_book_data(remote_id) mapped_data = dict_from_mappings(data, self.book_mappings) if self.is_work_data(data): try: @@ -150,6 +150,14 @@ class AbstractConnector(AbstractMinimalConnector): load_more_data.delay(self.connector.id, work.id) return edition + def get_book_data(self, remote_id): + """ this allows connectors to override the default behavior """ + return get_data(remote_id) + + def get_search_data(self, remote_id): + """ this allows connectors to override the default behavior """ + return get_data(remote_id) + def create_edition_from_data(self, work, edition_data): """ if we already have the work, we're ready """ mapped_data = dict_from_mappings(edition_data, self.book_mappings) @@ -176,7 +184,7 @@ class AbstractConnector(AbstractMinimalConnector): if existing: return existing - data = get_data(remote_id) + data = self.get_book_data(remote_id) mapped_data = dict_from_mappings(data, self.author_mappings) activity = activitypub.Author(**mapped_data) diff --git a/bookwyrm/connectors/inventaire.py b/bookwyrm/connectors/inventaire.py index 748259eb..72ed8221 100644 --- a/bookwyrm/connectors/inventaire.py +++ b/bookwyrm/connectors/inventaire.py @@ -1,8 +1,6 @@ """ inventaire data connector """ -from bookwyrm import models from .abstract_connector import AbstractConnector, SearchResult, Mapping from .abstract_connector import get_data -from .connector_manager import ConnectorException class Connector(AbstractConnector): @@ -26,6 +24,11 @@ class Connector(AbstractConnector): Mapping("goodreadsKey", remote_field="wdt:P2969", formatter=get_claim), ] + def get_book_data(self, remote_id): + data = get_data(remote_id) + extracted = list(data.get("entities").values()) + return extracted[0] if extracted else {} + def parse_search_data(self, data): return data.get('results') @@ -49,7 +52,7 @@ class Connector(AbstractConnector): """ beep bloop """ def is_work_data(self, data): - return True + return data.get("type") == "work" def get_edition_from_work_data(self, data): return {}