Untitled

 avatar
unknown
plain_text
a year ago
912 B
4
Indexable
import requests

def fetch_all_sr_rounds(base_url):
    sr_rounds = []
    from_id = 1
    limit = 10
    while True:
        # Prepare the URL with the current fromId and limit
        url = f"{base_url}?fromId={from_id}&limit={limit}"
        # Make the GET request
        response = requests.get(url)
        # Check if the request was successful
        if response.status_code != 200:
            print(f"Failed to fetch data: {response.status_code}")
            break
        # Parse the JSON response
        data = response.json()
        # Check if there are no more rounds to fetch
        if not data:
            break
        # Add the fetched rounds to our list
        sr_rounds.extend(data)
        # Update fromId for the next loop iteration
        from_id = data[-1]['id'] + 1
    return sr_rounds

# Usage
base_url = "..."
all_sr_rounds = fetch_all_sr_rounds(base_url)
print(all_sr_rounds)
Editor is loading...
Leave a Comment