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.
()
| 20 | |
| 21 | |
| 22 | def 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 | |
| 53 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…