mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Merge pull request #1030 from bookwyrm-social/author-data
Fixes getting authors from work data
This commit is contained in:
commit
7c81825527
2 changed files with 10 additions and 10 deletions
|
@ -122,7 +122,6 @@ class AbstractConnector(AbstractMinimalConnector):
|
|||
|
||||
# load the json
|
||||
data = self.get_book_data(remote_id)
|
||||
mapped_data = dict_from_mappings(data, self.book_mappings)
|
||||
if self.is_work_data(data):
|
||||
try:
|
||||
edition_data = self.get_edition_from_work_data(data)
|
||||
|
@ -130,24 +129,26 @@ class AbstractConnector(AbstractMinimalConnector):
|
|||
# hack: re-use the work data as the edition data
|
||||
# this is why remote ids aren't necessarily unique
|
||||
edition_data = data
|
||||
work_data = mapped_data
|
||||
work_data = data
|
||||
else:
|
||||
edition_data = data
|
||||
try:
|
||||
work_data = self.get_work_from_edition_data(data)
|
||||
work_data = dict_from_mappings(work_data, self.book_mappings)
|
||||
except (KeyError, ConnectorException):
|
||||
work_data = mapped_data
|
||||
except (KeyError, ConnectorException) as e:
|
||||
logger.exception(e)
|
||||
work_data = data
|
||||
|
||||
if not work_data or not edition_data:
|
||||
raise ConnectorException("Unable to load book data: %s" % remote_id)
|
||||
|
||||
with transaction.atomic():
|
||||
# create activitypub object
|
||||
work_activity = activitypub.Work(**work_data)
|
||||
work_activity = activitypub.Work(
|
||||
**dict_from_mappings(work_data, self.book_mappings)
|
||||
)
|
||||
# this will dedupe automatically
|
||||
work = work_activity.to_model(model=models.Work)
|
||||
for author in self.get_authors_from_data(data):
|
||||
for author in self.get_authors_from_data(work_data):
|
||||
work.authors.add(author)
|
||||
|
||||
edition = self.create_edition_from_data(work, edition_data)
|
||||
|
|
|
@ -137,9 +137,8 @@ class Connector(AbstractConnector):
|
|||
return self.get_book_data(self.get_remote_id(uri))
|
||||
|
||||
def get_work_from_edition_data(self, data):
|
||||
try:
|
||||
uri = data["claims"]["wdt:P629"]
|
||||
except KeyError:
|
||||
uri = data.get("wdt:P629", [None])[0]
|
||||
if not uri:
|
||||
raise ConnectorException("Invalid book data")
|
||||
return self.get_book_data(self.get_remote_id(uri))
|
||||
|
||||
|
|
Loading…
Reference in a new issue