Skip to content

Instantly share code, notes, and snippets.

@nikolasco
Created September 26, 2009 19:59
Show Gist options
  • Save nikolasco/194393 to your computer and use it in GitHub Desktop.
Save nikolasco/194393 to your computer and use it in GitHub Desktop.
<?php
header ("Content-type: text/css");
/* SET: yahoo rss weather feed */
$myWeatherURL = "http://weather.yahooapis.com/forecastrss?p=UKXX0215";
$fh = fopen($myWeatherURL, 'r');
// get the line we're interested in
$currentconditions = -1;
while ($theData = fgets($fh))
{
$currentconditions = strpos($theData, "<weather:condition text=");
if (strlen($currentconditions) > 0)
{
$data = explode("\"", $theData);
$currentweather = $data[3];
break; /* no need to look at the rest! */
}
}
fclose($fh);
switch($currentweather) {
case 0: /* tornado */
case 1: /* tropical storm */
case 2: /* hurricane */
case 3200: /* not available */
case -1: /* finding the conditions in the HTML failed... */
default: /* everything not explicitly listed... */
$css = "apocalypse.css";
break;
case 3: /* severe thunderstorms */
case 4: /* thunderstorms */
case 37: /* isolated thunderstorms */
case 38: /* scattered thunderstorms */
case 39: /* scattered thunderstorms */
case 45: /* thundershowers */
case 48: /* isolated thundershowers */
$css = "thunder.css";
break;
case 5: /* mixed rain and snow */
case 6: /* mixed rain and sleet */
case 7: /* mixed snow and sleet */
case 8: /* freezing drizzle */
case 10: /* freezing rain */
case 17: /* hail */
case 18: /* sleet */
case 25: /* cold */
case 35: /* mixed rain and hail */
$css = "cold-sleety-snow.css";
break;
case 9: /* drizzle */
case 11: /* showers */
case 12: /* showers */
case 40: /* scattered showers */
$css = "thunder.css";
break;
case 13: /* snow flurries */
case 14: /* light snow showers */
case 15: /* blowing snow */
case 16: /* snow */
case 41: /* heavy snow */
case 42: /* scattered snow showers */
case 43: /* heavy snow */
case 46: /* snow showers */
$css = "snow.css";
break;
case 19: /* dust */
case 20: /* foggy */
case 21: /* haze */
case 22: /* smoky */
$css = "nice-day.css";
break;
case 23: /* blustery */
case 24: /* windy */
$css = "cloudy-day.css";
break;
case 26: /* cloudy */
case 28: /* mostly cloudy (day) */
case 30: /* partly cloudy (day) */
case 44: /* partly cloudy */
$css = "cloudy-day.css";
break;
case 27: /* mostly cloudy (night) */
case 29: /* partly cloudy (night) */
$css = "cloudy-day.css";
break;
case 32: /* sunny */
case 34: /* fair (day) */
case 36: /* hot */
$css = "nice-day.css";
break;
case 31: /* clear (night) */
case 33: /* fair (night) */
$css = "nice-night.css";
break;
}
/* print out the right CSS! */
readfile($css);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment