Created
July 23, 2021 19:58
-
-
Save zaneselvans/9e226ab464359cfd2ee08f054ae969c4 to your computer and use it in GitHub Desktop.
Pull all EPA Facility latitudes and longitudes from the FACT API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import urllib3 | |
import pandas as pd | |
from urllib3 import request | |
import certifi | |
import json | |
url = f"https://api.epa.gov/FACT/1.0/facilities?api_key={os.environ['API_KEY_EPA_FACT']}" | |
http = urllib3.PoolManager( | |
cert_reqs='CERT_REQUIRED', | |
ca_certs=certifi.where() | |
) | |
r = http.request("GET", url) | |
assert r.status == 200 | |
data = json.loads(r.data.decode('utf-8')) | |
df = pd.json_normalize(data, record_path="data")[[ | |
"orisCode", | |
"name", | |
"geographicLocation.isValid", | |
"geographicLocation.latitude", | |
"geographicLocation.longitude", | |
]] | |
df = df.rename(columns={ | |
"orisCode": "plant_id_eia", | |
"name": "plant_name_eia", | |
"geographicLocation.isValid": "valid_location", | |
"geographicLocation.latitude": "latitude", | |
"geographicLocation.longitude": "longitude", | |
}) | |
df.info() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment