-
-
Save Kais-Alabdallah/34b9f90794357b3b77617a4dddee21ac 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment