Created
April 3, 2011 03:05
-
-
Save oknoway/900143 to your computer and use it in GitHub Desktop.
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
function getWeather() { | |
if (false === ( $theWeather = get_transient('theWeather') ) ) { | |
$xmlUrl = 'http://www.google.com/ig/api?weather=portland&oe=utf-8&'; | |
$output = wp_remote_fopen($xmlUrl); | |
$xmlData = simplexml_load_string($output); | |
$conditions = $xmlData->weather->current_conditions->condition['data']; | |
$raining = array( 'Showers', 'Scattered Showers', 'Chance of Rain', 'Chance of Storm', 'Rain', 'Light Rain' ); | |
$cloudy = array( 'Overcast', 'Cloudy' ); | |
$partly_cloudy = array( 'Partly Cloudy', 'Mostly Cloudy', 'Mist', 'Dust', 'Fog', 'Smoke', 'Haze' ); | |
$sunny = array( 'Sunny', 'Clear', 'Partly Sunny', 'Mostly Sunny' ); | |
$lightning = array( 'Scattered Thunderstorms', 'Storm', 'Thunderstorm', 'Chance of Tstorm' ); | |
$snowing = array( 'Rain and Snow', 'Light Snow', 'Freezing Drizzle', 'Chance of Snow', 'Sleet', 'Snow', 'Icy', 'Flurries' ); | |
if ( in_array( $conditions, $raining ) ) : | |
$theWeather = 'raining'; | |
elseif ( in_array( $conditions, $cloudy ) ) : | |
$theWeather = 'cloudy'; | |
elseif ( in_array( $conditions, $partly_cloudy ) ) : | |
$theWeather = 'partly-cloudy'; | |
elseif ( in_array( $conditions, $sunny ) ) : | |
$theWeather = 'sunny'; | |
elseif ( in_array( $conditions, $lightning ) ) : | |
$theWeather = 'lightning'; | |
elseif ( in_array( $conditions, $snowing ) ) : | |
$theWeather = 'snowing'; | |
else : | |
$theWeather = 'raining'; | |
endif; | |
set_transient('theWeather', $theWeather, 60*30); | |
} | |
return $theWeather; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment