Skip to content

Instantly share code, notes, and snippets.

@piotr-piatkowski
Created November 9, 2021 12:14
Show Gist options
  • Save piotr-piatkowski/105a667082ad9967508b1aa8d2017cac to your computer and use it in GitHub Desktop.
Save piotr-piatkowski/105a667082ad9967508b1aa8d2017cac to your computer and use it in GitHub Desktop.
#!/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