array("city" => "City1", "state" => "S1"), "TokenID 2" => array("city" => "City2", "state" => "S2"), "TokenID 3" => array("city" => "City3", "state" => "S3") ); // WeatherUnderground API Key $wu_apikey = "Your WU API Key"; // check if core is allowed if (in_array($core_id,$allowedCores)){ echo getWindData($wu_apikey, $token_id, $locations); } else { echo "API Key unknown. Access denied."; } function getWindData($apiKey, $tokenId, $location_array) { // get location city,state from locations array using token_id $state = $location_array[$tokenId]['state']; $city = $location_array[$tokenId]['city']; $wind_deg = 0; // query api using city, state, API key $postURL = "http://api.wunderground.com/api/".$apiKey."/conditions/q/".$state."/".$city.".json"; $json = file_get_contents($postURL); $data = json_decode($json,true); // pull wind info from json response $wind_mph = $data['current_observation']['wind_mph']; $wind_dir = $data['current_observation']['wind_dir']; switch($wind_dir) { case 'North': $wind_deg = 0; break; case 'NNE': $wind_deg = 22; break; case 'NE': $wind_deg = 45; break; case 'ENE': $wind_deg = 67; break; case 'East': $wind_deg = 90; break; case 'ESE': $wind_deg = 112; break; case 'SE': $wind_deg = 135; break; case 'SSE': $wind_deg = 157; break; case 'South': $wind_deg = 180; break; case 'SSW': $wind_deg = 202; break; case 'SW': $wind_deg = 225; break; case 'WSW': $wind_deg = 247; break; case 'West': $wind_deg = 270; break; case 'WNW': $wind_deg = 292; break; case 'NW': $wind_deg = 315; break; case 'NNW': $wind_deg = 337; break; } $wind_data = array('wind_dir' => $wind_deg, 'wind_mph' => $wind_mph); // return wind array return json_encode($wind_data); } ?>