HydroGen-APP / data_fetcher.py
mjolnir1122's picture
Update data_fetcher.py
31e917d verified
raw
history blame contribute delete
911 Bytes
import requests
import pandas as pd
import os
# Set your NREL API key here or use environment variables
NREL_API_KEY = "L0l8YMg3shJjkOS9kBAUCsbDglzJ0uYd8wMCNBdT" # Replace with your actual API key
def get_hydrogen_data():
"""
Fetch hydrogen station data from the NREL API.
"""
url = f"https://developer.nrel.gov/api/alt-fuel-stations/v1.json?limit=10&api_key={NREL_API_KEY}"
try:
response = requests.get(url)
response.raise_for_status() # Raise an error for HTTP status codes 4xx or 5xx
data = response.json()
if "fuel_stations" in data and len(data["fuel_stations"]) > 0:
return data["fuel_stations"]
else:
print("⚠️ No hydrogen data available from NREL API.")
return None
except requests.exceptions.RequestException as e:
print(f"❌ API Request Failed: {e}")
return None