Skip to content

Commit 2014764

Browse files
Update google_books.py
1 parent 790acec commit 2014764

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

consuming-apis-python/google_books.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import requests
22

33
endpoint = "https://www.googleapis.com/books/v1/volumes"
4-
params = {"q": "moby dick", "maxResults": 3}
54

5+
# Define the search term you want to use.
6+
query = "moby dick"
7+
8+
# In the query parameters you can define:
9+
# 1. The number of books to return using the `maxResults` parameter.
10+
# 2. The query term to search for using the `q` parameter.
11+
params = {"q": query, "maxResults": 3}
12+
13+
# The response will contain a list of books that match your query.
614
response = requests.get(endpoint, params=params).json()
715
for book in response["items"]:
16+
# In order to fetch the title, published date and description, you first need to fetch the volume.
817
volume = book["volumeInfo"]
18+
19+
# You can fetch these and other attributes from the book using the specific volume
920
title = volume["title"]
1021
published = volume["publishedDate"]
1122
description = volume["description"]

0 commit comments

Comments
 (0)