import requests # Authenticate via `/token` endpoint access_token = "your_access_token_here" headers = { 'Authorization': f'Bearer {access_token}', 'Accept': 'application/json' } # Challenge resource name. resource_name = "wind_farm_1" # Retrieve datetime range: start_datetime = "2025-01-01T00:00:00Z" end_datetime = "2026-01-01T00:00:00Z" # Get challenges target resource identifier (UUID) # (this is also available via the /market/challenge/ endpoint ) response = requests.get( url='https://predico-elia.inesctec.pt/api/v1/user/resource', params={'resource_name': resource_name}, headers=headers ) # Check if the request was successful if response.status_code == 200: resources = response.json() else: print("Failed to retrieve resource data.") print(f"Status code: {response.status_code}") print(f"Response: {response.content}") exit() # Get resource ID: resource_id = resources["data"][0]["id"] print("Resource ID:", resource_id) # Download continuous forecasts data for this resource: params = { "resource": resource_id, "start_date": start_datetime, "end_date": end_datetime } next_url = "https://predico-elia.inesctec.pt/api/v1/data/continuous-forecasts" dataset = [] # -- Note: This will stop once all the samples are retrieved. # -- next_url indicates the URL of the next page (pagination) to be requested) while next_url is not None: print(f"Requesting data...\n{next_url}") # This may take a while response = requests.get(url=next_url, params=params, headers=headers) print("Response status code:", response.status_code) # Check if the request was successful if response.status_code != 200: print("Failed to retrieve forecasts.") print(f"Status code: {response.status_code}") print(f"Response: {response.content}") exit("Exiting...") else: dataset += response.json()["data"]["results"] next_url = response.json()["data"]["next"] # -- Note: This will stop once all the samples are retrieved. print("-"*79) print(f"Retrieved {len(dataset)} records") print("Continuous forecasts data (first 10 records preview):") print(dataset[:10])