Get more data out of openlibrary

This commit is contained in:
Mouse Reeve
2020-03-27 21:28:52 -07:00
parent 5c475e448a
commit 51e7a50b86
5 changed files with 143 additions and 28 deletions

View File

@ -4,6 +4,35 @@ from fedireads.settings import DOMAIN
def get_book(book):
''' activitypub serialize a book '''
fields = [
'sort_title',
'subtitle',
'isbn',
'oclc_number',
'openlibrary_key',
'librarything_key',
'fedireads_key',
'lccn',
'isbn',
'oclc_number',
'pages',
'physical_format',
'misc_identifiers',
'source_url',
'sync',
'last_sync_date',
'description',
'language',
'series',
'series_number',
'subjects',
'subject_places',
'pages',
'physical_format',
]
activity = {
'@context': 'https://www.w3.org/ns/activitystreams',
'type': 'Document',
@ -11,30 +40,17 @@ def get_book(book):
'name': book.title,
'url': book.absolute_id,
'sort_title': book.sort_title,
'subtitle': book.subtitle,
'openlibrary_key': book.openlibrary_key,
'librarything_key': book.librarything_key,
'fedireads_key': book.fedireads_key,
'misc_identifiers': book.misc_identifiers,
'source_url': book.source_url,
'sync': book.sync,
'last_sync_date': book.last_sync_date,
'description': book.description,
'language': book.language,
'series': book.series,
'series_number': book.series_number,
'authors': [get_author(a) for a in book.authors.all()],
'first_published_date': book.first_published_date.isoformat() if \
book.first_published_date else None,
'published_date': book.published_date.isoformat() if \
book.published_date else None,
'parent_work': book.parent_work.absolute_id if \
book.parent_work else None,
'authors': [get_author(a) for a in book.authors.all()],
}
for field in fields:
if hasattr(book, field):
activity[field] = book.__getattribute__(field)
if book.cover:
image_path = book.cover.url
@ -45,7 +61,7 @@ def get_book(book):
'url': 'https://%s%s' % (DOMAIN, image_path),
'name': 'Cover of "%s"' % book.title,
}]
return {k: v for (k, v) in activity.items() if v}
return {k: v for (k, v) in activity.items() if v}
def get_author(author):