Skip to content

Instantly share code, notes, and snippets.

@zaneselvans
Created July 23, 2021 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaneselvans/9e226ab464359cfd2ee08f054ae969c4 to your computer and use it in GitHub Desktop.
Save zaneselvans/9e226ab464359cfd2ee08f054ae969c4 to your computer and use it in GitHub Desktop.
Pull all EPA Facility latitudes and longitudes from the FACT API
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