Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- # 1. Update to the brand new official Data.gov Catalog v4 API endpoint
- url = "https://api.gsa.gov/technology/datagov/v4/search"
- # Note: 'DEMO_KEY' is built-in for testing purposes
- params = {
- 'sort': 'last_harvested_date',
- 'per_page': 1,
- 'api_key': 'DEMO_KEY'
- }
- try:
- response = requests.get(url, params=params, timeout=15)
- response.raise_for_status()
- data = response.json()
- # Extract data from the new response body structure
- datasets = data.get('results', [])
- if datasets:
- latest_dataset = datasets[0]
- dataset_name = latest_dataset.get('title', 'No title found')
- harvest_date = latest_dataset.get('last_harvested_date', 'Unknown date')
- print("\n--- Success! ---")
- print(f"Most recently updated dataset: {dataset_name}")
- print(f"Last Harvested Date: {harvest_date}")
- else:
- print("No datasets found matching your parameters.")
- except requests.exceptions.RequestException as e:
- print(f"Error fetching data from the server: {e}")
- except ValueError:
- print("Error: The server still failed to parse JSON.")
Advertisement
Add Comment
Please, Sign In to add comment