Skip to content

Instantly share code, notes, and snippets.

@AO8
Last active April 7, 2024 13:20
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save AO8/faa3f52d3d5eac63820cfa7ec2b24aa7 to your computer and use it in GitHub Desktop.
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.
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
@Kais-Alabdallah
Copy link

Hallo,
If the search is for the name not just for the ISBN, What should be changed or written?

Best Wish,
Kais

@maxkleiner
Copy link

@Bigjango13
Copy link

Could this be changed to output genre(s)?

@vimagick
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment