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 g
(book_details)
| 34 | return category_raw[3:] |
| 35 | |
| 36 | def validate_bookcover(book_details): |
| 37 | """ |
| 38 | Check if goodreads returns a nophoto |
| 39 | Use open library to fetch the book cover |
| 40 | based on ISBN |
| 41 | |
| 42 | Args: |
| 43 | book_details: Book info returned as json by goodreads API |
| 44 | |
| 45 | Returns: |
| 46 | This API checks for book cover, and returns with a valid |
| 47 | bookcover if nophoto found on goodreads, using openlibrary |
| 48 | """ |
| 49 | no_photo_url='https://s.gr-assets.com/assets/nophoto/book/' |
| 50 | open_library_url='http://covers.openlibrary.org/b/isbn/{isbn}-M.jpg' |
| 51 | |
| 52 | if (book_details['image_url'].__contains__(no_photo_url)): |
| 53 | book_details['image_url'] = open_library_url.format(isbn=book_details['isbn']) |
| 54 | return book_details |
| 55 | |
| 56 | if __name__ == "__main__": |
| 57 | library = load("../README.md", "new") |