Skip to content

Commit

Permalink
Fix 403s
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire authored Jul 9, 2023
1 parent 314751e commit 3e9eeb6
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions calfire_wildfires/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ def get_active_fires():
Returns GeoJSON with point geometry
"""

print("Requesting active Fires")
# Request data
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36", # noqa
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", # noqa
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", # noqa
}
r = requests.get(
"https://www.fire.ca.gov/umbraco/api/IncidentApi/GeoJsonList?inactive=false",
headers=headers,
)
if r.status_code != 200:
url = "https://www.fire.ca.gov/umbraco/api/IncidentApi/GeoJsonList?inactive=false"
r = requests.get(url, headers=headers)

# Make sure get a good response
try:
assert r.ok
except AssertionError:
raise Exception(f"Request for data failed with {r.status_code} status code")

# Return it
return r.json()

Expand All @@ -33,8 +32,17 @@ def get_all_fires():
Returns GeoJSON with point geometry
"""
# Request data
r = requests.get("https://www.fire.ca.gov/umbraco/api/IncidentApi/GeoJsonList")
if r.status_code != 200:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", # noqa
}
url = "https://www.fire.ca.gov/umbraco/api/IncidentApi/GeoJsonList"
r = requests.get(url, headers=headers)

# Make sure the response works
try:
assert r.ok
except AssertionError:
raise Exception(f"Request for data failed with {r.status_code} status code")

# Return it
return r.json()

0 comments on commit 3e9eeb6

Please sign in to comment.