|
|
|
@ -19,15 +19,15 @@ if (empty($VARS["nocache"])) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$json = file_get_contents("https://api.openweathermap.org/data/2.5/onecall?lat=$lat&lon=$lon&units=imperial&appid=" . env("openweathermap_appid", ""));
|
|
|
|
|
$json = file_get_contents("https://api.darksky.net/forecast/" . env("darksky_apikey", "") . "/$lat,$lon?units=us&exclude=alerts,flags");
|
|
|
|
|
$weather = json_decode($json, TRUE);
|
|
|
|
|
|
|
|
|
|
$minutely = [];
|
|
|
|
|
|
|
|
|
|
foreach ($weather["minutely"] as $m) {
|
|
|
|
|
foreach ($weather["minutely"]["data"] as $m) {
|
|
|
|
|
$minutely[] = [
|
|
|
|
|
"time" => $m["dt"],
|
|
|
|
|
"precip" => round($m["precipitation"] / 25.4, 3)
|
|
|
|
|
"time" => $m["time"],
|
|
|
|
|
"precip" => round($m["precipIntensity"], 3)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$hourly = [];
|
|
|
|
@ -43,42 +43,42 @@ $oldicon = "clear";
|
|
|
|
|
$nowicon = "clear";
|
|
|
|
|
$lasttimestamp = time();
|
|
|
|
|
|
|
|
|
|
foreach ($weather["hourly"] as $w) {
|
|
|
|
|
if ($w["dt"] > strtotime("now + " . env("weather_summary_hours", 8) . " hours")) {
|
|
|
|
|
foreach ($weather["hourly"]["data"] as $w) {
|
|
|
|
|
if ($w["time"] > strtotime("now + " . env("weather_summary_hours", 8) . " hours")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$hourly[] = [
|
|
|
|
|
"time" => $w["dt"],
|
|
|
|
|
"temp" => $w["temp"],
|
|
|
|
|
"feelslike" => $w["feels_like"],
|
|
|
|
|
"windspeed" => $w["wind_speed"],
|
|
|
|
|
"winddirection" => $w["wind_deg"],
|
|
|
|
|
"precipchance" => $w["pop"]
|
|
|
|
|
"time" => $w["time"],
|
|
|
|
|
"temp" => $w["temperature"],
|
|
|
|
|
"feelslike" => $w["apparentTemperature"],
|
|
|
|
|
"windspeed" => $w["windSpeed"],
|
|
|
|
|
"winddirection" => $w["windBearing"],
|
|
|
|
|
"precipchance" => $w["precipProbability"]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ($mintemp === false) {
|
|
|
|
|
$mintemp = $w["temp"];
|
|
|
|
|
$mintemp = $w["temperature"];
|
|
|
|
|
}
|
|
|
|
|
if ($maxtemp === false) {
|
|
|
|
|
$maxtemp = $w["temp"];
|
|
|
|
|
$maxtemp = $w["temperature"];
|
|
|
|
|
}
|
|
|
|
|
if ($maxwind === false) {
|
|
|
|
|
$maxwind = $w["wind_speed"];
|
|
|
|
|
$maxwind = $w["windSpeed"];
|
|
|
|
|
}
|
|
|
|
|
if ($precipchance === false) {
|
|
|
|
|
$precipchance = $w["pop"];
|
|
|
|
|
$precipchance = $w["precipProbability"];
|
|
|
|
|
}
|
|
|
|
|
if ($maxcloudcover === false) {
|
|
|
|
|
$maxcloudcover = $w["clouds"];
|
|
|
|
|
$maxcloudcover = $w["cloudCover"] * 100.0;
|
|
|
|
|
}
|
|
|
|
|
$mintemp = min($w["temp"], $mintemp);
|
|
|
|
|
$maxtemp = max($w["temp"], $maxtemp);
|
|
|
|
|
$maxwind = max($w["wind_speed"], $maxwind);
|
|
|
|
|
$precipchance = max($w["pop"], $precipchance);
|
|
|
|
|
$maxcloudcover = max($w["clouds"], $maxcloudcover);
|
|
|
|
|
$cloudcovers[] = $w["clouds"];
|
|
|
|
|
$lasttimestamp = max($w["dt"], $lasttimestamp);
|
|
|
|
|
$mintemp = min($w["temperature"], $mintemp);
|
|
|
|
|
$maxtemp = max($w["temperature"], $maxtemp);
|
|
|
|
|
$maxwind = max($w["windSpeed"], $maxwind);
|
|
|
|
|
$precipchance = max($w["precipProbability"], $precipchance);
|
|
|
|
|
$maxcloudcover = max($w["cloudCover"] * 100.0, $maxcloudcover);
|
|
|
|
|
$cloudcovers[] = $w["cloudCover"];
|
|
|
|
|
$lasttimestamp = max($w["time"], $lasttimestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$avgcloudcover = array_sum($cloudcovers) / count($cloudcovers);
|
|
|
|
@ -106,45 +106,35 @@ if ($precipchance > 0.2) {
|
|
|
|
|
$oldicon = "partly-cloudy";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (((string) $weather["current"]["weather"][0]["id"])[0] == "2") {
|
|
|
|
|
if ($weather["currently"]["icon"] == "rain") {
|
|
|
|
|
$nowicon = "rain";
|
|
|
|
|
} else if (((string) $weather["current"]["weather"][0]["id"])[0] == "3") {
|
|
|
|
|
$nowicon = "rain";
|
|
|
|
|
} else if (((string) $weather["current"]["weather"][0]["id"])[0] == "5") {
|
|
|
|
|
$nowicon = "rain";
|
|
|
|
|
} else if (((string) $weather["current"]["weather"][0]["id"])[0] == "6") {
|
|
|
|
|
} else if ($weather["currently"]["icon"] == "snow") {
|
|
|
|
|
$nowicon = "snow";
|
|
|
|
|
} else if (((string) $weather["current"]["weather"][0]["id"])[0] == "7") {
|
|
|
|
|
} else if ($weather["currently"]["icon"] == "fog") {
|
|
|
|
|
$nowicon = "fog";
|
|
|
|
|
if ($weather["current"]["weather"][0]["id"] == 781) {
|
|
|
|
|
// Tornado!!!
|
|
|
|
|
$nowicon = "hazard";
|
|
|
|
|
}
|
|
|
|
|
} else if ($weather["current"]["weather"][0]["id"] == 801) {
|
|
|
|
|
$nowicon = "mostly-sunny";
|
|
|
|
|
} else if ($weather["current"]["weather"][0]["id"] == 802) {
|
|
|
|
|
} else if ($weather["currently"]["icon"] == "partly-cloudy-day" || $weather["currently"]["icon"] == "partly-cloudy-night") {
|
|
|
|
|
$nowicon = "partly-cloudy";
|
|
|
|
|
} else if ($weather["current"]["weather"][0]["id"] >= 803) {
|
|
|
|
|
} else if ($weather["currently"]["icon"] == "cloudy") {
|
|
|
|
|
$nowicon = "cloudy";
|
|
|
|
|
}
|
|
|
|
|
if (($nowicon == "mostly-sunny" || $nowicon == "clear" || $nowicon == "partly-cloudy") && $weather["current"]["feels_like"] > 80) {
|
|
|
|
|
if (($nowicon == "mostly-sunny" || $nowicon == "clear" || $nowicon == "partly-cloudy") && $weather["currently"]["apparentTemperature"] > 80) {
|
|
|
|
|
$nowicon = "heat";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dailyforecast = [];
|
|
|
|
|
|
|
|
|
|
foreach ($weather["daily"] as $w) {
|
|
|
|
|
foreach ($weather["daily"]["data"] as $w) {
|
|
|
|
|
$dailyforecast[] = [
|
|
|
|
|
"date" => $w["dt"],
|
|
|
|
|
"date" => $w["time"],
|
|
|
|
|
"temp" => [
|
|
|
|
|
"min" => $w["temp"]["min"],
|
|
|
|
|
"max" => $w["temp"]["max"]
|
|
|
|
|
"min" => $w["temperatureLow"],
|
|
|
|
|
"max" => $w["temperatureHigh"]
|
|
|
|
|
],
|
|
|
|
|
"precipitation" => [
|
|
|
|
|
"chance" => empty($w["pop"]) ? 0 : $w["pop"]
|
|
|
|
|
"chance" => empty($w["precipProbability"]) ? 0 : $w["precipProbability"]
|
|
|
|
|
],
|
|
|
|
|
"windspeed" => $w["wind_speed"],
|
|
|
|
|
"uv_index" => round($w["uvi"], 1)
|
|
|
|
|
"windspeed" => $w["windSpeed"],
|
|
|
|
|
"uv_index" => round($w["uvIndex"], 1)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -205,11 +195,11 @@ $output = [
|
|
|
|
|
],
|
|
|
|
|
"now" => [
|
|
|
|
|
"icon" => $nowicon,
|
|
|
|
|
"temp" => $weather["current"]["temp"],
|
|
|
|
|
"feelslike" => $weather["current"]["feels_like"],
|
|
|
|
|
"uv_index" => (is_null($epa_uv_index) ? min(round($weather["current"]["uvi"], 1), 11) : $epa_uv_index),
|
|
|
|
|
"windspeed" => $weather["current"]["wind_speed"],
|
|
|
|
|
"winddirection" => $weather["current"]["wind_deg"]
|
|
|
|
|
"temp" => $weather["currently"]["temperature"],
|
|
|
|
|
"feelslike" => $weather["currently"]["apparentTemperature"],
|
|
|
|
|
"uv_index" => (is_null($epa_uv_index) ? min(round($weather["currently"]["uvIndex"], 1), 11) : $epa_uv_index),
|
|
|
|
|
"windspeed" => $weather["currently"]["windSpeed"],
|
|
|
|
|
"winddirection" => $weather["currently"]["windBearing"]
|
|
|
|
|
],
|
|
|
|
|
"today" => [
|
|
|
|
|
"minutely" => $minutely,
|
|
|
|
@ -236,8 +226,8 @@ $output = [
|
|
|
|
|
"latitude" => $lat,
|
|
|
|
|
"longitude" => $lon,
|
|
|
|
|
"source" => [
|
|
|
|
|
"text" => "Data: OpenWeatherMap.org" . (is_null($epa_uv_index) ? "" : ", EPA"),
|
|
|
|
|
"url" => "https://openweathermap.org"
|
|
|
|
|
"text" => "Powered by Dark Sky" . (is_null($epa_uv_index) ? "" : ", EPA"),
|
|
|
|
|
"url" => "https://darksky.net/poweredby/"
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|