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