MCPcopy Create free account
hub / github.com/googleapis/google-api-python-client / main

Function main

samples/searchforshopping/pagination.py:22–50  ·  view source on GitHub ↗

Get and print a the entire paginated feed of public products in the United States. Pagination is controlled with the "startIndex" parameter passed to the list method of the resource.

()

Source from the content-addressed store, hash-verified

20
21
22def main():
23 """Get and print a the entire paginated feed of public products in the United
24 States.
25
26 Pagination is controlled with the "startIndex" parameter passed to the list
27 method of the resource.
28 """
29 client = build("shopping", SHOPPING_API_VERSION, developerKey=DEVELOPER_KEY)
30 resource = client.products()
31 # The first request contains the information we need for the total items, and
32 # page size, as well as returning the first page of results.
33 request = resource.list(source="public", country="US", q="digital camera")
34 response = request.execute()
35 itemsPerPage = response["itemsPerPage"]
36 totalItems = response["totalItems"]
37 for i in range(1, totalItems, itemsPerPage):
38 answer = input(
39 "About to display results from %s to %s, y/(n)? " % (i, i + itemsPerPage)
40 )
41 if answer.strip().lower().startswith("n"):
42 # Stop if the user has had enough
43 break
44 else:
45 # Fetch this series of results
46 request = resource.list(
47 source="public", country="US", q="digital camera", startIndex=i
48 )
49 response = request.execute()
50 pprint.pprint(response)
51
52
53if __name__ == "__main__":

Callers 1

pagination.pyFile · 0.70

Calls 2

buildFunction · 0.90
executeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…