forked from mirrors/bookwyrm
Use custom data extractor for inventaire connector
This commit is contained in:
parent
fba44206ac
commit
22ebe60c0a
2 changed files with 18 additions and 7 deletions
|
@ -44,7 +44,7 @@ class AbstractMinimalConnector(ABC):
|
||||||
if min_confidence:
|
if min_confidence:
|
||||||
params["min_confidence"] = min_confidence
|
params["min_confidence"] = min_confidence
|
||||||
|
|
||||||
data = get_data(
|
data = self.get_search_data(
|
||||||
"%s%s" % (self.search_url, query),
|
"%s%s" % (self.search_url, query),
|
||||||
params=params,
|
params=params,
|
||||||
)
|
)
|
||||||
|
@ -57,7 +57,7 @@ class AbstractMinimalConnector(ABC):
|
||||||
def isbn_search(self, query):
|
def isbn_search(self, query):
|
||||||
""" isbn search """
|
""" isbn search """
|
||||||
params = {}
|
params = {}
|
||||||
data = get_data(
|
data = self.get_search_data(
|
||||||
"%s%s" % (self.isbn_search_url, query),
|
"%s%s" % (self.isbn_search_url, query),
|
||||||
params=params,
|
params=params,
|
||||||
)
|
)
|
||||||
|
@ -117,7 +117,7 @@ class AbstractConnector(AbstractMinimalConnector):
|
||||||
return existing
|
return existing
|
||||||
|
|
||||||
# load the json
|
# load the json
|
||||||
data = get_data(remote_id)
|
data = self.get_book_data(remote_id)
|
||||||
mapped_data = dict_from_mappings(data, self.book_mappings)
|
mapped_data = dict_from_mappings(data, self.book_mappings)
|
||||||
if self.is_work_data(data):
|
if self.is_work_data(data):
|
||||||
try:
|
try:
|
||||||
|
@ -150,6 +150,14 @@ class AbstractConnector(AbstractMinimalConnector):
|
||||||
load_more_data.delay(self.connector.id, work.id)
|
load_more_data.delay(self.connector.id, work.id)
|
||||||
return edition
|
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):
|
def create_edition_from_data(self, work, edition_data):
|
||||||
""" if we already have the work, we're ready """
|
""" if we already have the work, we're ready """
|
||||||
mapped_data = dict_from_mappings(edition_data, self.book_mappings)
|
mapped_data = dict_from_mappings(edition_data, self.book_mappings)
|
||||||
|
@ -176,7 +184,7 @@ class AbstractConnector(AbstractMinimalConnector):
|
||||||
if existing:
|
if existing:
|
||||||
return existing
|
return existing
|
||||||
|
|
||||||
data = get_data(remote_id)
|
data = self.get_book_data(remote_id)
|
||||||
|
|
||||||
mapped_data = dict_from_mappings(data, self.author_mappings)
|
mapped_data = dict_from_mappings(data, self.author_mappings)
|
||||||
activity = activitypub.Author(**mapped_data)
|
activity = activitypub.Author(**mapped_data)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
""" inventaire data connector """
|
""" inventaire data connector """
|
||||||
from bookwyrm import models
|
|
||||||
from .abstract_connector import AbstractConnector, SearchResult, Mapping
|
from .abstract_connector import AbstractConnector, SearchResult, Mapping
|
||||||
from .abstract_connector import get_data
|
from .abstract_connector import get_data
|
||||||
from .connector_manager import ConnectorException
|
|
||||||
|
|
||||||
|
|
||||||
class Connector(AbstractConnector):
|
class Connector(AbstractConnector):
|
||||||
|
@ -26,6 +24,11 @@ class Connector(AbstractConnector):
|
||||||
Mapping("goodreadsKey", remote_field="wdt:P2969", formatter=get_claim),
|
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):
|
def parse_search_data(self, data):
|
||||||
return data.get('results')
|
return data.get('results')
|
||||||
|
|
||||||
|
@ -49,7 +52,7 @@ class Connector(AbstractConnector):
|
||||||
""" beep bloop """
|
""" beep bloop """
|
||||||
|
|
||||||
def is_work_data(self, data):
|
def is_work_data(self, data):
|
||||||
return True
|
return data.get("type") == "work"
|
||||||
|
|
||||||
def get_edition_from_work_data(self, data):
|
def get_edition_from_work_data(self, data):
|
||||||
return {}
|
return {}
|
||||||
|
|
Loading…
Reference in a new issue