Created
October 16, 2014 02:29
-
-
Save chrisblakley/c5598cbb33d6fcd032f5 to your computer and use it in GitHub Desktop.
Querying current weather conditions to make it rain or snow on your site.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="bgimgweather"> | |
<?php | |
$url = 'http://w1.weather.gov/xml/current_obs/KSYR.xml'; | |
$xml = simplexml_load_file($url); | |
$currentweather = $xml->weather; | |
//$currentweather = "Light Rain"; | |
?> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch (true) { | |
case stristr( $currentweather, "Thunderstorm" ): | |
echo '<div class="bgimgrain"></div>'; | |
echo '<div class="bgimgstorm"></div>'; | |
break; | |
case stristr( $currentweather, "Snow" ): | |
echo '<div class="bgimgsnow"></div>'; | |
break; | |
case stristr( $currentweather, "Rain" ): | |
case stristr( $currentweather, "Drizzle" ): | |
case stristr( $currentweather, "Hail" ): | |
case stristr( $currentweather, "Showers" ): | |
echo '<div class="bgimgrain"></div>'; | |
break; | |
case stristr( $currentweather, "Fog" ): | |
case stristr( $currentweather, "Haze" ): | |
case stristr( $currentweather, "Smoke" ): | |
echo '<div class="bgimgfog"></div>'; | |
break; | |
default: | |
//Do Nothing | |
break; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.bgimgstorm {position: absolute; top: 0; background: url('img/weather/storm.gif') repeat left top; width: 100%; height: 100%; opacity: 0.2;} | |
.bgimgsnow {background: url('img/weather/snow.gif') repeat left top; width: 100%; height: 100%;} | |
.bgimgrain {background: url('img/weather/rain.gif') repeat left top; width: 100%; height: 100%;} | |
.bgimgfog {background: url('img/weather/fog.png') repeat-x left top; width: 100%; height: 100%;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'http://w1.weather.gov/xml/current_obs/KSYR.xml'; | |
$xml = simplexml_load_file($url); | |
$currentweather = $xml->weather; | |
//$currentweather = "Light Rain"; | |
switch (true) { | |
case stristr( $currentweather, "Light" ): | |
case stristr( $currentweather, "Drizzle" ): | |
echo '.bgimgfog {opacity: 0.3;} '; | |
echo '.bgimgrain {opacity: 0.04;} '; | |
echo '.bgimgsnow {opacity: 0.04;} '; | |
echo '/*' . $currentweather . '*/'; | |
break; | |
case stristr( $currentweather, "Heavy" ): | |
case stristr( $currentweather, "Thunderstorm" ): | |
echo '.bgimgfog {opacity: 0.9;} '; | |
echo '.bgimgrain {opacity: 0.1;} '; | |
echo '.bgimgsnow {opacity: 0.2;} '; | |
echo '/*' . $currentweather . '*/'; | |
break; | |
default: | |
echo '.bgimgfog {opacity: 0.5;} '; | |
echo '.bgimgrain {opacity: 0.07;} '; | |
echo '.bgimgsnow {opacity: 0.08;} '; | |
echo '/* ' . $currentweather . ' */'; | |
break; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment