Updating Python code to work with cursor-based relative pagination

vslorenz
New Member
1 0 0

Hello,

Our team has been notified that our app will stop working on April 1, 2021 because we'd be calling an unsupported API. We found the problem to be that we needed to update our app to use cursor-based relative pagination. Some background: our team is very bare bones and has been decimated by Covid. I am a novice programmer but have had issues troubleshooting our code.

Here is the code that worked and that we used prior to needing to make this change: 

def get_all_resources(resource, **kwargs):

    resource_count = resource.count(**kwargs)
    print("site members: [{}]".format(resource_count))
    resources = []
    if resource_count > 0:
        totalPages = ((resource_count - 1) // 250) + 2
        for page in range(1, totalPages):
            print("reading results page [{}]/[{}]".format(page, totalPages))
            kwargs.update({"limit": 250, "page": page})
            resources.extend(resource.find(**kwargs))
    return resources

Here is the code that we are attempting to use that is not working for us: 

def get_all_resources(resource, **kwargs):
    resource_count = resource.count(**kwargs)
    resources = []
    if resource_count > 0:
        page=resource.find(**kwargs)
        resources.extend(page)
        while page.has_next_page():
            page = page.next_page()
            resources.extend(page)
    return resources

As I mentioned, I'm a pretty novice programmer, especially in Python, and it is solely up to me to solve this prior to April 1. Any help here would be incredibly appreciated! Thank you!

Replies 0 (0)