|
aohavkbs, http://www.tomshw.it/forum/members/buy-glucophage.html glucophage conveniente, tndgogaw, http://www.tomshw.it/forum/members/comprar-zyprexa.html zyprexa conveniente, vtyyhpgn, http://www.tomshw.it/forum/members/comprar-desyrel.html desyrel conveniente, fxjgwxxe, http://www.tomshw.it/forum/members/comprar-cytotec.html cytotec prezzo ridotto, sazxpbxj, |
Assignment2EricFReverse weather Online version: http://ernie.art.yale.edu/~ericfeng/final/weathermatch3.php Source code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Weather Match</title> <style type="text/css"> <!-- body { background-color: #666666; height: 40px; list-style-type: disc; cursor: nw-resize; } .style1 { font-size: 11px; color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; } --> </style> </head> <body> <!-- draw the pull-down menu --> <form action="weathermatch.php" method="get"> <div align="right"> <table width="231" height="40" border="0" cellpadding="0" cellspacing="2"> <tr> <td width="85" height="23"><div align="center"><span class="style1">Where is my </span></div></td> <td width="83" height="23"><select name="select"> <option selected="selected"></option> <option>Freezing</option> <option>Cold</option> <option>Lovely</option> <option>Warm</option> <option>Hottest</option> </select></td> <td width="55"><span class="style1">weahter ? </span></td> </tr> </table> <select name="temperature"> <option value="0">below 0 F°</option> <option value="1,10">0-10 F°</option> <option value="11,20">11-20 F°</option> <option value="21,30">21-30 F°</option> <option value="31,40">31-40 F°</option> <option value="41,50">41-50 F°</option> <option value="51,60">51-60 F°</option> <option value="61,70">61-70 F°</option> <option value="71,80">71-80 F°</option> <option value="81,90">81-90 F°</option> <option value="91,100">91-100 F°</option> <option value="101">above 100 F°</option> </select> <!-- submit button --> <input type="submit" value="find it!"> </div> </form> <?php // if we have input from the form, query yahoo weather for results if (isset($_REQUEST["temperature"])) { $selection = $_REQUEST["temperature"]; $temp_choice = preg_split("/,/",$selection); $colors = array( // color range from dark to light in hex values '0,-10' => array("7FCED1","99D8DA","A5DDD1","7FCED1","B2E2E3","BFE6E8","CCEBED","D8F0F1","E5F5F6"), '1,10' => array("000000","191919","333333","4c4c4c","666666","7F7F7F","999999","B2B2B2","CCCCCC"), '11,21' => array("10006c","27197a","403389","4c4c4c","547c98","7066a7","877fb5","9f99c4","cfcce2"), '21,30' => array("0a0781","221f99","3b39a5","5351b0","6c6abb","8583c6","9c9dd2","b5b4dd","cecde8"), '31,40' => array("0e346c","26487A","3E5D89","6E85A7","8699B5","9FAEC4","B6D2d3","CFD6e2","E6EAF0"), '41,50' => array("176C60","2E7A70","458980","5C988F","74A7A0","8BB5AF","A2C4BF","B9D3CF","D1E2DF"), '51,60' => array("23B440","39BB19","4FC333","65CA4C","7BD266","91D97F","A7E199","BDE8B2","D3F0CC"), '61,70' => array("568F00","679AE9","78A533","88B04C","9ABC66","AAC77F","BBD299","CCBBD2","DDE9CC"), '71,80' => array("8A4900","955B19","A16D33","AD7F4C","B99266","C4A47F","D0B699","DCC8B2","E8DBCC"), '81,90' => array("D14600","D65819","DA6B33","DFCD4C","D39066","E8A27F","DEB599","F1C7B2","F6DACC"), '91,100' => array("AB0004","83191D","BC3336","C44C4F","CD6668","D57F81","DD999B","E6B2B3","EECCCD"), '101' => array("FF0000","99D8DA","A5DDD1","7FCED1","B2E2E3","BFE6E8","CCEBED","D8F0F1","E5F5F6"), ); $cities = array( '96815', // honolulu '10021', // new york '06511', // new haven '10520', // croton '94511', '30339', // honolulu '96734', // new york '00601', // new haven '96754', // croton '07097', '90001', '92101', '85001', '30301', '07023', '07946', '08836', '11030', '12022', '98953', '98323', '97625', '97035', '95951', '95420', '94566', '93435', '92346', '91324', '76652', '89103', '78108', '78717', '79502', '80449', '81235', '94566', '74571', '75226', '76006' ); $city_array = array(); $temp_array = array(); $city_temp = array(); foreach ($cities as $zip) { // first step: get data $yahoo_url = "http://xml.weather.yahoo.com/forecastrss?p=$zip"; $data = file_get_contents($yahoo_url); // reformat yahoo weather data $data = str_replace("yweather:", "", $data); $data = str_replace("geo:", "", $data); // load reformatted file into SimpleXML $xml_data = simplexml_load_string($data); // second step: create variables // <channel> node contains some of the info $channel = $xml_data->channel; $units = $channel->units; $tempUnits = $units["temperature"]; $location = $channel->location; $city = $location["city"]; // e.g. "New Haven" // <item> node is within the <channel> node, contains additional info $item = $channel->item; $condition = $item->condition; $temp = $condition["temp"]; // e.g. 57 // Wind data: only the attributes are meaningful $wind = $channel->wind; $windChill = $wind["chill"]; // e.g. "57" $windDir = $wind["direction"]; // e.g. "350" $windSpeed = $wind["speed"]; // e.g. "7" // Atmosphere data: only the attributes are meaningful $atmosphere = $channel->atmosphere; $humidity = $atmosphere["humidity"]; // e.g. "93"; $visibility = $atmosphere["visibility"]; // e.g. "1609"; $pressure = $atmosphere["pressure"]; // e.g. "30.12"; $rising = $atmosphere["rising"]; // e.g. "0"; // Astronomy data: only the attributes are meaningful $astronomy = $channel->astronomy; $sunrise = $astronomy["sunrise"]; // e.g. "7:02 am"; $sunset = $astronomy["sunset"]; // e.g. "4:51 pm"; array_push($city_array,$city); array_push($temp_array,$temp); $city_temp = array_combine($city_array,$temp_array); } foreach ($city_temp as $city=>$temp) { if (($temp >= $temp_choice[0]) and ($temp <= $temp_choice[1])) { $matching_cities[$city] = $temp; } } foreach ($matching_cities as $city=>$temp) { // takes second digit from two-digit temperture (23 -> 3) $temp_color_index = substr($temp, 1); $temp_color_index = $temp_color_index - 1; $hex_value = $colors[$selection][$temp_color_index]; // if we have results, draw the temperature display echo "\n\n"; echo '<div style="font-size:45px; font-family: Georgia, sans-serif; width:75%; padding:30px; color:#ffffff; background-color:#' . $hex_value . ';">'; echo "$city "; echo '<div style="font-size:30px; font-family: Verdana, Arial, Helvetica, sans-serif; width:100px; padding:10px; color:#ffffff; background-color:#' . $hex_value . ';">'; echo "$temp "; echo "<strong>F°</strong>"; echo '</div>'; echo '<div style="font-size:10px; font-family: Georgia, sans-serif; width:100px; padding:10px; color:#ffffff; background-color:#' . $hex_value . ';">'; echo "Wind $windSpeed $windUnits at $windDir°. "; echo "\n\n"; echo "Pressure $pressure $pressureUnits. "; echo "\n\n"; echo "Sunset at $sunset. "; echo "\n\n\n"; echo '</div>'; } } ?> </body> </html> |