gitignore, energy)layer fix

This commit is contained in:
2026-05-15 20:49:51 -07:00
parent f57969c9ee
commit 4e6a564b6c
3 changed files with 87 additions and 2 deletions

View File

@@ -80,6 +80,11 @@ EIA_GEOCODABLE_ENDPOINTS = {
"electricity/facility-fuel": ["latitude", "longitude"],
}
# Endpoints that do not reliably support retry with ad-hoc data[] field requests.
EIA_NO_RETRY_EXTRA_FIELDS = {
"electricity/facility-fuel",
}
# US state abbreviation to FIPS code mapping for state-level GEOID linking
STATE_FIPS = {
"AL": "01", "AK": "02", "AZ": "04", "AR": "05", "CA": "06",
@@ -138,7 +143,7 @@ def query_eia_api(endpoint: str, params: Optional[Dict[str, Any]] = None, extra_
req_params[f"data[{i}]"] = field
try:
resp = requests.get(url, params=req_params, timeout=60)
resp = requests.get(url, params=req_params, timeout=(10, 20))
resp.raise_for_status()
return resp.json()
except requests.RequestException as e:
@@ -163,7 +168,11 @@ def fetch_eia_records(
data = query_eia_api(endpoint, params=params, extra_data_fields=used_extra_fields)
# Some endpoints return 400 when requesting unsupported fields (e.g. lat/lon).
if data is None and used_extra_fields:
if (
data is None
and used_extra_fields
and endpoint not in EIA_NO_RETRY_EXTRA_FIELDS
):
print(f" retrying {endpoint} without extra data fields")
used_extra_fields = None
data = query_eia_api(endpoint, params=params, extra_data_fields=None)