Use openlibrary api when goodreads returns nophoto
This commit is contained in:
@@ -33,6 +33,25 @@ def clean_category(category_raw):
|
||||
if "## " in category_raw:
|
||||
return category_raw[3:]
|
||||
|
||||
def validate_bookcover(book_details):
|
||||
"""
|
||||
Check if goodreads returns a nophoto
|
||||
Use open library to fetch the book cover
|
||||
based on ISBN
|
||||
|
||||
Args:
|
||||
book_details: Book info returned as json by goodreads API
|
||||
|
||||
Returns:
|
||||
This API checks for book cover, and returns with a valid
|
||||
bookcover if nophoto found on goodreads, using openlibrary
|
||||
"""
|
||||
no_photo_url='https://s.gr-assets.com/assets/nophoto/book/111x148-bcc042a9c91a29c1d680899eff700a03.png'
|
||||
open_library_url='http://covers.openlibrary.org/b/isbn/book_isbn-M.jpg'
|
||||
|
||||
if (book_details['image_url'] == no_photo_url):
|
||||
book_details['image_url'] = open_library_url.replace('book_isbn', book_details['isbn'])
|
||||
return book_details
|
||||
|
||||
if __name__ == "__main__":
|
||||
library = load("../README.md", "new")
|
||||
@@ -55,6 +74,7 @@ if __name__ == "__main__":
|
||||
fetched = get_details(new_book)
|
||||
if fetched:
|
||||
print(f"✅ {title}")
|
||||
new_book = validate_bookcover(new_book)
|
||||
existing_book_names_to_details[title] = new_book
|
||||
with open("book_name_to_details.json", "w") as f:
|
||||
json.dump(
|
||||
|
||||
Reference in New Issue
Block a user