Fix error when fetching UV index

master
Skylar Ittner 2 years ago
parent d8f9e19940
commit 55f0842b60

@ -160,9 +160,15 @@ if ($geocode["status"] == "OK") {
$city = $geocode["address"]["city"];
$state = $geocode["address"]["state"];
try {
$epa_url = "https://enviro.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/CITY/$city/STATE/$state/JSON";
$epa_data = json_decode(ApiFetcher::get($epa_url), true);
$epauv = $memcache->get("gis.weather.epauv.$state.$city");
if ($epauv !== false) {
$epa_data = json_decode($epauv, true);
} else {
$epa_url = "https://enviro.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/CITY/$city/STATE/$state/JSON";
$epa_json = file_get_contents($epa_url);
$epa_data = json_decode($epa_json, true);
$memcache->set("gis.weather.epauv.$state.$city", $epa_json, 60 * 60 * 4);
}
// Find which returned result is closest to the current date and time
$closest = $epa_data[0];

Loading…
Cancel
Save