-
Notifications
You must be signed in to change notification settings - Fork 0
/
iceAndFire03.py
32 lines (25 loc) · 1.09 KB
/
iceAndFire03.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python3
"""Alta3 Research - Exploring OpenAPIs with requests"""
# documentation for this API is at
# https://anapioficeandfire.com/Documentation
import requests
AOIF_BOOKS = "https://www.anapioficeandfire.com/api/books"
def main():
## Send HTTPS GET to the API of ICE and Fire books resource
gotresp = requests.get(AOIF_BOOKS)
## Decode the response
got_dj = gotresp.json()
## loop across response
for singlebook in got_dj:
## display the names of each book
## all of the below statements do the same thing
#print(singlebook["name"] + ",", "pages -", singlebook["numberOfPages"])
#print("{}, pages - {}".format(singlebook["name"], singlebook["numberOfPages"]))
print(f"{singlebook['name']}, pages - {singlebook['numberOfPages']}")
print(f"\tAPI URL -> {singlebook['url']}\n")
# print ISBN
print(f"\tISBN -> {singlebook['isbn']}\n")
print(f"\tPUBLISHER -> {singlebook['publisher']}\n")
print(f"\tNo. of CHARACTERS -> {len(singlebook['characters'])}\n")
if __name__ == "__main__":
main()