Created
November 9, 2021 12:14
-
-
Save piotr-piatkowski/105a667082ad9967508b1aa8d2017cac to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python3 | |
import json | |
import requests | |
def get_by_keys(res, *keys): | |
try: | |
for k in keys: | |
res = res[k] | |
return res | |
except (TypeError, KeyError, IndexError): | |
return None | |
r = requests.get('https://www.googleapis.com/books/v1/volumes?q=hobbit') | |
for book in r.json()['items']: | |
print(get_by_keys(book, 'volumeInfo', 'industryIdentifiers', 0, 'identifier')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment