Last active
January 23, 2020 10:41
-
-
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
This file contains hidden or 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 | |
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