Given Open Library book data, return a summary as a Python dict.
(ol_book_data: dict)
| 38 | |
| 39 | |
| 40 | def summarize_book(ol_book_data: dict) -> dict: |
| 41 | """ |
| 42 | Given Open Library book data, return a summary as a Python dict. |
| 43 | """ |
| 44 | desired_keys = { |
| 45 | "title": "Title", |
| 46 | "publish_date": "Publish date", |
| 47 | "authors": "Authors", |
| 48 | "number_of_pages": "Number of pages", |
| 49 | "isbn_10": "ISBN (10)", |
| 50 | "isbn_13": "ISBN (13)", |
| 51 | } |
| 52 | data = {better_key: ol_book_data[key] for key, better_key in desired_keys.items()} |
| 53 | data["Authors"] = [ |
| 54 | get_openlibrary_data(author["key"])["name"] for author in data["Authors"] |
| 55 | ] |
| 56 | for key, value in data.items(): |
| 57 | if isinstance(value, list): |
| 58 | data[key] = ", ".join(value) |
| 59 | return data |
| 60 | |
| 61 | |
| 62 | if __name__ == "__main__": |
no test coverage detected