Last active
November 5, 2024 01:18
-
-
Save AO8/faa3f52d3d5eac63820cfa7ec2b24aa7 to your computer and use it in GitHub Desktop.
A simple ISBN lookup that uses Python and the Google Books API to display basic information about a book.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import json | |
import textwrap | |
while True: | |
base_api_link = "https://www.googleapis.com/books/v1/volumes?q=isbn:" | |
user_input = input("Enter ISBN: ").strip() | |
with urllib.request.urlopen(base_api_link + user_input) as f: | |
text = f.read() | |
decoded_text = text.decode("utf-8") | |
obj = json.loads(decoded_text) # deserializes decoded_text to a Python object | |
volume_info = obj["items"][0] | |
authors = obj["items"][0]["volumeInfo"]["authors"] | |
# displays title, summary, author, domain, page count and language | |
print("\nTitle:", volume_info["volumeInfo"]["title"]) | |
print("\nSummary:\n") | |
print(textwrap.fill(volume_info["searchInfo"]["textSnippet"], width=65)) | |
print("\nAuthor(s):", ",".join(authors)) | |
print("\nPublic Domain:", volume_info["accessInfo"]["publicDomain"]) | |
print("\nPage count:", volume_info["volumeInfo"]["pageCount"]) | |
print("\nLanguage:", volume_info["volumeInfo"]["language"]) | |
print("\n***") | |
status_update = input("\nEnter another ISBN? y or n: ").lower().strip() | |
if status_update == "n": | |
print("\nThank you! Have a nice day.") | |
break |
Just change the API-link to name:
https://www.googleapis.com/books/v1/volumes?q=%22patterns%20konkret%22
Could this be changed to output genre(s)?
📖 Here is the API Doc: https://developers.google.com/books/docs/v1/using#WorkingVolumes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hallo,
If the search is for the name not just for the ISBN, What should be changed or written?
Best Wish,
Kais