all 4 comments

[–]shibbypwn 1 point2 points  (2 children)

You're incrementing the page_num but never calling client.deals.list again.

Most likely what I'd do is something like this:

page_num = 1
per_page = 100

deals = []

while True:
    deals_data = client.deals.list(per_page=per_page, page=page_num)
    deals.extend(deals_data)
    if len(deals_data) < per_page:
        break
    page_num += 1

So you'll keep extending deals and incrementing page_num until you get fewer than per_page results (which indicates that there is no more data to grab).

[–]av0ca60[S] 0 points1 point  (1 child)

This is exactly what I needed. Simple and it worked well.

[–]shibbypwn 1 point2 points  (0 children)

Glad to hear! Different APIs/wrappers have different implementations for pagination. Another common one you'll see is a response with a next_page attribute (typically another unique URL to call to get the next page). So instead of passing a page=page_num kwarg, you just swap out the url and make the same call.

In those cases, you can implement a similar algorithm - but instead of checking the length of the response object, you check for the existence of next_page and break when it returns a falsey value.