import requests import json from datetime import datetime, timedelta def get_iceout_data(): # 1. Define the endpoint url = "https://iceout.org/api/reports/" # 2. Set the time range (e.g., last 24 hours) now = datetime.utcnow() yesterday = now - timedelta(days=1) # Format dates as ISO 8601 strings params = { "archived": "False", "incident_time__gte": yesterday.strftime("%Y-%m-%dT%H:%M:%S.000Z"), "incident_time__lte": now.strftime("%Y-%m-%dT%H:%M:%S.000Z") } # 3. Mimic the Headers from the HAR file # The 'X-API-Version' and 'User-Agent' are critical. headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36", "X-API-Version": "1.4", "Accept": "application/json", # Force server to return JSON, not MsgPack "Referer": "https://iceout.org/en/" } try: # 4. Make the Request response = requests.get(url, headers=headers, params=params) response.raise_for_status() # 5. Parse and Print Data data = response.json() # Depending on the response structure (list or object), print the results if isinstance(data, list): print(f"Found {len(data)} reports.") for report in data[:3]: # Print first 3 as a sample print(f"ID: {report.get('id')}") print(f"Location: {report.get('location_description')}") print(f"Description: {report.get('activity_description')}") print("-" * 30) else: # Sometimes APIs return a wrapper object print("Response received:") print(json.dumps(data, indent=2)) except requests.exceptions.RequestException as e: print(f"Error fetching data: {e}") if __name__ == "__main__": get_iceout_data()