From: Stephen Jianu Date: Sun, 23 Mar 2025 14:05:09 +0000 (-0500) Subject: Wrap everything in PHP tags and reduce API calls to just one X-Git-Url: https://stephenjianu.com/gitweb/?a=commitdiff_plain;h=d7332ade9ba47c7ea908256596fa9c58f9ec8945;p=reasonableweather.git Wrap everything in PHP tags and reduce API calls to just one --- diff --git a/index.php b/index.php index 097c011..4696d2e 100644 --- a/index.php +++ b/index.php @@ -1,48 +1,43 @@ - - - - Weather in Park Ridge - - -

The current conditions in Park Ridge are:

-

-
".$description."
"."0°"; - ?> -

-

Your 7 day forecast for Park Ridge is:

- "; - echo "

"; - echo "".date('l', strtotime($json["daily"]["time"][$i]))."
"; - echo "

"; - echo "".$description."
"; - echo "High: ".$tempHighConverted."°"; - echo "
"; - echo "Low: ".$tempLowConverted."°"; - echo ""; - } - echo "

"; - ?> - This site uses the MJM weather system, the most accurate weather system in the world, for measuring temperature. We source our weather from the National Weather Service and give you pure, unmodified data. - - +\n"; + echo "\n"; + echo "\n"; + echo "Weather in Park Ridge\n"; + echo "\n"; + echo "\n"; + echo "

The current conditions in Park Ridge are:

\n"; + echo "

\n"; + $url = "https://api.open-meteo.com/v1/forecast?latitude=42.0111&longitude=-87.8406&daily=temperature_2m_max,temperature_2m_min,weather_code¤t=temperature_2m,weather_code,is_day&timezone=America%2FChicago&wind_speed_unit=mph&temperature_unit=fahrenheit&precipitation_unit=inch"; + $json = json_decode(file_get_contents($url), true); + $jsonDescriptions = json_decode(file_get_contents("descriptions.json"), true); + $code = $json["current"]["weather_code"]; + $isDay = ($json["current"]["is_day"]) ? "day" : "night"; + $description = $jsonDescriptions[$code][$isDay]["description"]; + $image = $jsonDescriptions[$code][$isDay]["image"]; + echo "
".$description."
"."0°\n"; + echo "

\n"; + echo "

Your 7 day forecast for Park Ridge is:

\n"; + $tempNow = $json["current"]["temperature_2m"]; + for ($i = 0; $i < 7; $i++) { + $code = $json["daily"]["weather_code"][$i]; + $description = $jsonDescriptions[$code]["day"]["description"]; + $image = $jsonDescriptions[$code]["day"]["image"]; + $tempHigh = $json["daily"]["temperature_2m_max"][$i]; + $tempHighConverted = $tempHigh - $tempNow; + $tempLow = $json["daily"]["temperature_2m_min"][$i]; + $tempLowConverted = $tempLow - $tempNow; + echo "
\n"; + echo "

\n"; + echo "".date('l', strtotime($json["daily"]["time"][$i]))."
\n"; + echo "

\n"; + echo "".$description."
\n"; + echo "High: ".$tempHighConverted."°\n"; + echo "
\n"; + echo "Low: ".$tempLowConverted."°\n"; + echo "
\n"; + } + echo "

\n"; + echo "This site uses the MJM weather system, the most accurate weather system in the world, for measuring temperature. We source our weather from the National Weather Service and give you pure, unmodified data.\n"; + echo "\n"; + echo "\n"; +?>