forked from mirrors/bookwyrm
Fixes search data and new activitypub fields
This commit is contained in:
parent
82c2f2eeb1
commit
4112862924
3 changed files with 22 additions and 19 deletions
|
@ -7,7 +7,17 @@ from .image import Image
|
|||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Book(ActivityObject):
|
||||
class BookData(ActivityObject):
|
||||
""" shared fields for all book data and authors"""
|
||||
openlibraryKey: str = None
|
||||
inventaireId: str = None
|
||||
librarythingKey: str = None
|
||||
goodreadsKey: str = None
|
||||
bnfId: str = None
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Book(BookData):
|
||||
""" serializes an edition or work, abstract """
|
||||
|
||||
title: str
|
||||
|
@ -24,11 +34,6 @@ class Book(ActivityObject):
|
|||
firstPublishedDate: str = ""
|
||||
publishedDate: str = ""
|
||||
|
||||
openlibraryKey: str = None
|
||||
inventaireId: str = None
|
||||
librarythingKey: str = None
|
||||
goodreadsKey: str = None
|
||||
|
||||
cover: Image = None
|
||||
type: str = "Book"
|
||||
|
||||
|
@ -61,17 +66,16 @@ class Work(Book):
|
|||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Author(ActivityObject):
|
||||
class Author(BookData):
|
||||
""" author of a book """
|
||||
|
||||
name: str
|
||||
isni: str = None
|
||||
viafId: str = None
|
||||
gutenbergId: str = None
|
||||
born: str = None
|
||||
died: str = None
|
||||
aliases: List[str] = field(default_factory=lambda: [])
|
||||
bio: str = ""
|
||||
openlibraryKey: str = None
|
||||
inventaireId: str = None
|
||||
librarythingKey: str = None
|
||||
goodreadsKey: str = None
|
||||
wikipediaLink: str = ""
|
||||
type: str = "Author"
|
||||
|
|
|
@ -68,6 +68,10 @@ class AbstractMinimalConnector(ABC):
|
|||
results.append(self.format_isbn_search_result(doc))
|
||||
return results
|
||||
|
||||
def get_search_data(self, remote_id, **kwargs): # pylint: disable=no-self-use
|
||||
""" this allows connectors to override the default behavior """
|
||||
return get_data(remote_id, **kwargs)
|
||||
|
||||
@abstractmethod
|
||||
def get_or_create_book(self, remote_id):
|
||||
""" pull up a book record by whatever means possible """
|
||||
|
@ -154,10 +158,6 @@ class AbstractConnector(AbstractMinimalConnector):
|
|||
""" this allows connectors to override the default behavior """
|
||||
return get_data(remote_id)
|
||||
|
||||
def get_search_data(self, remote_id): # pylint: disable=no-self-use
|
||||
""" 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)
|
||||
|
|
|
@ -14,7 +14,6 @@ class Connector(AbstractConnector):
|
|||
shared_mappings = [
|
||||
Mapping("id", remote_field="uri", formatter=self.get_remote_id),
|
||||
Mapping("bnfId", remote_field="wdt:P268", formatter=get_first),
|
||||
Mapping("oclcNumber", remote_field="wdt:P5331", formatter=get_first),
|
||||
Mapping("openlibraryKey", remote_field="wdt:P648", formatter=get_first),
|
||||
]
|
||||
self.book_mappings = [
|
||||
|
@ -24,6 +23,7 @@ class Connector(AbstractConnector):
|
|||
Mapping("cover", remote_field="image", formatter=self.get_cover_url),
|
||||
Mapping("isbn13", remote_field="wdt:P212", formatter=get_first),
|
||||
Mapping("isbn10", remote_field="wdt:P957", formatter=get_first),
|
||||
Mapping("oclcNumber", remote_field="wdt:P5331", formatter=get_first),
|
||||
Mapping("goodreadsKey", remote_field="wdt:P2969", formatter=get_first),
|
||||
Mapping("librarythingKey", remote_field="wdt:P1085", formatter=get_first),
|
||||
# Mapping("languages", remote_field="wdt:P407", formatter=get_language),
|
||||
|
@ -38,7 +38,7 @@ class Connector(AbstractConnector):
|
|||
|
||||
self.author_mappings = [
|
||||
Mapping("id", remote_field="uri", formatter=self.get_remote_id),
|
||||
Mapping("name", remote_field="label", formatter=get_language_code),
|
||||
Mapping("name", remote_field="labels", formatter=get_language_code),
|
||||
Mapping("goodreadsKey", remote_field="wdt:P2963", formatter=get_first),
|
||||
Mapping("isni", remote_field="wdt:P213", formatter=get_first),
|
||||
Mapping("viafId", remote_field="wdt:P214", formatter=get_first),
|
||||
|
@ -62,8 +62,7 @@ class Connector(AbstractConnector):
|
|||
# flatten the data so that images, uri, and claims are on the same level
|
||||
return {
|
||||
**data.get("claims"),
|
||||
"uri": data.get("uri"),
|
||||
"image": data.get("image"),
|
||||
**{k: data.get(k) for k in ["uri", "image", "labels"]},
|
||||
}
|
||||
|
||||
def parse_search_data(self, data):
|
||||
|
|
Loading…
Reference in a new issue