From d7332ade9ba47c7ea908256596fa9c58f9ec8945 Mon Sep 17 00:00:00 2001 From: Stephen Jianu <stephen@stephenjianu.com> Date: Sun, 23 Mar 2025 09:05:09 -0500 Subject: [PATCH] Wrap everything in PHP tags and reduce API calls to just one --- index.php | 91 ++++++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/index.php b/index.php index 097c011..4696d2e 100644 --- a/index.php +++ b/index.php @@ -1,48 +1,43 @@ -<html> - <head> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Weather in Park Ridge</title> - </head> - <body style="text-align: center;"> - <h3>The current conditions in Park Ridge are:</h3> - <h1> - <?php - $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 "<img src=\"".$image."\"/><br>".$description."<br>"."0°"; - ?> - </h1> - <h3>Your 7 day forecast for Park Ridge is:</h3> - <?php - $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); - $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 "<div style=\"min-width: 10%; display: inline-block;\">"; - echo "<h3>"; - echo "".date('l', strtotime($json["daily"]["time"][$i]))."<br><img src=\"".$image."\"/>"; - echo "</h3>"; - echo "<span style=\"font-weight: bold;\">".$description."</span><br>"; - echo "<span style=\"font-weight: bold;\">High: </span>".$tempHighConverted."°"; - echo "<br>"; - echo "<span style=\"font-weight: bold;\">Low: </span>".$tempLowConverted."°"; - echo "</div>"; - } - echo "<br><br>"; - ?> - 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. - </body> -</html> +<?php + echo "<html>\n"; + echo "<head>\n"; + echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"; + echo "<title>Weather in Park Ridge</title>\n"; + echo "</head>\n"; + echo "<body style=\"text-align: center;\">\n"; + echo "<h3>The current conditions in Park Ridge are:</h3>\n"; + echo "<h1>\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 "<img src=\"".$image."\"/><br>".$description."<br>"."0°\n"; + echo "</h1>\n"; + echo "<h3>Your 7 day forecast for Park Ridge is:</h3>\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 "<div style=\"min-width: 10%; display: inline-block;\">\n"; + echo "<h3>\n"; + echo "".date('l', strtotime($json["daily"]["time"][$i]))."<br><img src=\"".$image."\"/>\n"; + echo "</h3>\n"; + echo "<span style=\"font-weight: bold;\">".$description."</span><br>\n"; + echo "<span style=\"font-weight: bold;\">High: </span>".$tempHighConverted."°\n"; + echo "<br>\n"; + echo "<span style=\"font-weight: bold;\">Low: </span>".$tempLowConverted."°\n"; + echo "</div>\n"; + } + echo "<br><br>\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 "</body>\n"; + echo "</html>\n"; +?> -- 2.39.5