Last active
November 9, 2021 11:43
-
-
Save piotr-piatkowski/7a1a16df7e84ed476bbe3b160e742762 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
def get_by_keys(res, *keys): | |
try: | |
for k in keys: | |
res = res[k] | |
return res | |
except (TypeError, KeyError, IndexError): | |
return None | |
book_data = { | |
'title': get_by_keys(result, 'volumeInfo', 'title'), | |
'authors': get_by_keys(result, 'volumeInfo', 'authors', 0), | |
'publish_date': get_by_keys(result, 'volumeInfo', 'publishedDate'), | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment