Skip to content

Instantly share code, notes, and snippets.

@housamz
Last active January 23, 2020 10:41
Show Gist options
  • Save housamz/8589e04a43314bae75925d5ca8b9a026 to your computer and use it in GitHub Desktop.
Save housamz/8589e04a43314bae75925d5ca8b9a026 to your computer and use it in GitHub Desktop.
Python requests script that queris Google books API for book info using ISBN
import urllib.request
import json
book_ISBN = "9780307277671"
google_api = "https://www.googleapis.com/books/v1/volumes?q=isbn:"
with urllib.request.urlopen(google_api + book_ISBN) as f:
text = f.read()
decoded_text = text.decode("utf-8")
obj = json.loads(decoded_text)
# the full data
# print(obj)
book_info = obj["items"][0]
# human-readable data
print("\nTitle:", book_info["volumeInfo"]["title"])
print("\nDescription:", book_info["volumeInfo"]["description"])
print("\nAuthor(s):", ",".join(book_info["volumeInfo"]["authors"]))
print("\nPages:", book_info["volumeInfo"]["pageCount"])
print("\nLanguage:", book_info["volumeInfo"]["language"])
print("\n########### Finished ###########")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment