Recent Changes - Search:

http://chance.ch/viewtopic.php?m=18&tp=63097&l=359 Oak Creek Veterinary Hospital http://chindershop.ch/viewtopic.php?m=21&tp=86107&l=681 Papal Rome 1718 http://careerprocess.info/viewtopic.php?m=55&tp=85557&l=932 Safeway Silverdale http://clown.ch/viewtopic.php?m=28&tp=23958&l=228 71st Infantry Ww1 Patch http://clown.ch/viewtopic.php?m=20&tp=26167&l=895 Abnormal Pap And Hpv http://christophsprenger.com/viewtopic.php?m=50&tp=41160&l=471 Cruze Titanium 2gb http://chance.ch/viewtopic.php?m=74&tp=58879&l=789 Nina H Ttinger http://centroesposizioni.ch/viewtopic.php?m=28&tp=78205&l=837 Towing Vessels In The Canadian Artic http://clown.ch/viewtopic.php?m=19&tp=23250&l=394 512mb Music http://capunz.ch/viewtopic.php?m=29&tp=88695&l=281 Wiccan Dollz http://clown.ch/viewtopic.php?m=71&tp=21591&l=405 3 Ergon Herman Miller http://clown.ch/viewtopic.php?m=57&tp=20872&l=615 2008 Suzuki Gsx1400r http://chasa-capol.ch/viewtopic.php?m=78&tp=55469&l=135 Lycopene Cantaloupe http://chance.ch/viewtopic.php?m=8&tp=61886&l=167 Nude Cheerrleaders http://chasa-capol.ch/viewtopic.php?m=37&tp=45050&l=789 Law Enforcement Gyrocopters http://chasa-capol.ch/viewtopic.php?m=17&tp=46945&l=118 Lena Brunsch http://cvp-fr.ch/viewtopic.php?m=98&tp=38779&l=381 Atrial Thrombus Atrial Fibrillation http://capunz.ch/viewtopic.php?m=24&tp=92946&l=332 Woods Otter http://careerprocess.info/viewtopic.php?m=46&tp=83829&l=799 Rufus Wainwright The Art Teacher http://clown.ch/viewtopic.php?m=92&tp=20014&l=582 2004 Ford Freestar Door Ajar Switch

Assignment2EricF

Reverse weather

Online version: http://ernie.art.yale.edu/~ericfeng/final/weathermatch3.php

Documentation book

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&deg;</option>
                <option value="1,10">0-10 F&deg;</option>
                <option value="11,20">11-20 F&deg;</option>
                <option value="21,30">21-30 F&deg;</option>
                <option value="31,40">31-40 F&deg;</option>
                <option value="41,50">41-50 F&deg;</option>
                <option value="51,60">51-60 F&deg;</option>
                <option value="61,70">61-70 F&deg;</option>
                <option value="71,80">71-80 F&deg;</option>
                <option value="81,90">81-90 F&deg;</option>
                <option value="91,100">91-100 F&deg;</option>
                <option value="101">above 100 F&deg;</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&deg;. ";
                echo "\n\n";
                echo "Pressure $pressure $pressureUnits. ";
                echo "\n\n";
                echo "Sunset at $sunset. ";
                echo "\n\n\n";
                echo '</div>';
        }
       
}

?>

</body>
</html>
 

Edit - History - Print - Recent Changes - Search
Page last modified on April 29, 2006, at 10:04 AM