Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 35

Thread: Weather.com SDK Module - Leet Add On!

  1. #21
    Join Date
    Jan 2004
    Location
    Chicago
    Posts
    54

    Default

    Got it working. Was using my old database name. Stupid Stupid Stupid....oh well, at least it is working. Thanks for all the input.

  2. #22
    Join Date
    Feb 2003
    Location
    Omaha
    Age
    42
    Posts
    73

    Default

    Quote Originally Posted by tcdrake
    Got it working. Was using my old database name. Stupid Stupid Stupid....oh well, at least it is working. Thanks for all the input.
    happens to the best of us. ryan can vouge for me being stupid all of the time.
    Best,
    Brad
    WWoBn Communications Group

  3. #23
    Join Date
    Feb 2005
    Location
    Flagstaff, Arizona, United States
    Age
    42
    Posts
    27

    Default

    I know I'm pulling up an old thread, but I figure its better than starting a new one. I am using this mod but am getting all sorts crazy things showing up. My icons under day in the forecast are night symbols, they have moons. It will say partly cloudy and have a snow icon..... Any help is appreciated!

    My table is verbatim to that listed in the instructions.

    My weather.php calls weather_xml by this line:
    Code:
    include("http://www.cosmorealtor.com/weather_xml.php?id=86001&length=10");
    My weather_xml is as follows. I only changed some color items within the file from the original. I rolled back to the original and the same problems occur.
    Code:
    <?
    
    // Setup database connection
    $db_host = "localhost";
    $db_user = "xxxx";
    $db_pwd = "xxxx";
    $db_name = "xxxx";
    $connection = mysql_connect($db_host, $db_user, $db_pwd) or die("Could not connect");
    mysql_select_db($db_name) or die("Could not select database");
    
    // Set Local variables
    $partner_ID = "xxxxx";
    $license_key = "xxxx";
    $location = urlencode($_REQUEST['loc']); //search on location (city or zip)
    $loc_id = $_REQUEST['id'];	// specific town id
    $length = $_REQUEST['length']; // Forecast length
    $image_size = "64x64"; // 32x32, 64x64, or 128x128 - size of daily weather images
    
    if (!($length >= 1 And $length <= 10)) $length = 10;
    
    $search_url = "http://xoap.weather.com/search/search?where=$location";
    $forecast_url = "http://xoap.weather.com/weather/local/$loc_id?cc=*&dayf=$length&prod=xoap&par=$partner_ID&key=$license_key";
    
    function html_header() // Write html header to screen
    {
    $header = <<< end_of_output
    <html>
    <head>
    <title></title>
    <style>
    <!--
    body, p      { font-size: 10pt; font-family: arial }
    td           { font-size: 10pt; font-family: arial }
    -->
    </style>
    </head>
    <body>
    end_of_output;
    echo $header;
    }
    
    if ($location) // Determine URL to use. If location is passed, we're searching for a city or zip. Elese we're retrieving a forecast.
    {
    	$url = $search_url;
    }
    else
    {
    	$url = $forecast_url;
    }
    
    if ($location Or $loc_id) 
    {
    
    	/* 
    	query db for md5 of url
    	if doesn't exist, insert into db
    	if exists, check date, if under X hours use db content
    	if older then X hours, pull from weather.com and update db
    
    	to delete old data: when querying, delete all records older than X hours
    	*/
    
    	$datetime = date("Y-m-d h:i:s");
    	$xml_url = md5($url);
    	$interval = 1;	// Hours to keep data in db before being considered old
    	$expires = $interval*60*60;
    	$expiredatetime = date("Y-m-d H:i:s", time() - $expires);
    
    	// Delete expired records
    	$query = "DELETE FROM weather_xml WHERE last_updated < '$expiredatetime'";
    	$result = mysql_query($query) or die('Invalid query: ' . mysql_error());
    
    	$query = "SELECT * FROM weather_xml WHERE xml_url = '$xml_url'"; 
    	$result = mysql_query($query) or die('Invalid query: ' . mysql_error());
    	$row = mysql_fetch_array($result);
    	$time_diff = strtotime($datetime) - strtotime($row['last_updated']);
    
    	if (mysql_num_rows($result) < 1) // Data not in table - Add.
    	{
    		// Get XML Query Results from Weather.com
    		$fp = fopen($url,"r");
    		while (!feof ($fp))
    			$xml .= fgets($fp, 4096);
    		fclose ($fp);
    
    		// Fire up the built-in XML parser
    		$parser = xml_parser_create(  ); 
    		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    
    		// Set tag names and values
    		xml_parse_into_struct($parser,$xml,$values,$index); 
    
    		// Close down XML parser
    		xml_parser_free($parser);
    
    		if ($loc_id) // Only inserts forecast feed, not search results feed, into db
    		{
    			$query = "INSERT INTO weather_xml VALUES ('$xml_url', '$xml', '$datetime')";
    			$result = mysql_query($query) or die('Invalid query: ' . mysql_error());
    		}
    
    	}
    	else // Data in table, and it is within expiration period - do not load from weather.com and use cached copy instead.
    	{
    		$xml = $row['xml_data'];
    
    		// Fire up the built-in XML parser
    		$parser = xml_parser_create(  ); 
    		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    
    		// Set tag names and values
    		xml_parse_into_struct($parser,$xml,$values,$index); 
    
    		// Close down XML parser
    		xml_parser_free($parser);
    	}
    
    	// Debugging output
    	//echo "<pre>";
    	//print_r($xml);
    	//print_r($index);
    	//print_r($values);
    	//echo "</pre>";
    }
    
    if ($loc_id) // Location code selected - Display detail info. A specific city has been selected from the drop down menu. Get forecast.
    {
    	$city = $values[$index[dnam][0]][value];
    	$unit_temp = $values[$index[ut][0]][value];
    	$unit_speed = $values[$index[us][0]][value];
    	$unit_precip = $values[$index[up][0]][value];
    	$unit_pressure = $values[$index[ur][0]][value];
    	$sunrise = $values[$index[sunr][0]][value];
    	$sunset = $values[$index[suns][0]][value];
    	$timezone = $values[$index[tzone][0]][value];
    	$last_update = $values[$index[lsup][0]][value];
    	$curr_temp = $values[$index[tmp][0]][value];
    	$curr_flik = $values[$index[flik][0]][value];
    	$curr_text = $values[$index[t][0]][value];
    	$curr_icon = $values[$index[icon][0]][value];
    	$counter = 0;
    	$row_counter = 2;
    
    	html_header(); // Output header
    	echo "Current weather and forecast provided by <a href='http://www.weather.com'>weather.com</a>. Weather information is specific to Flagstaff. For other regional weather just enter the city in the box below.</a>.<br><br>";
    	echo "<b><font size=4>Weather report for $city</font></b><br /><font size=1>(Last updated $last_update).</font><br />\n";
    	echo "<p><table><tr><td><img border=\"1\" src=\"/images/weather/128x128/$curr_icon.png\" alt=\"$curr_text\"></td><td>";
    	echo "<font size=3>Currently: <b>$curr_temp˚ $unit_temp</b></font>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />\n";
    	echo "Feels Like: $curr_flik˚ $unit_temp<br />Current conditions: $curr_text<br />\n";
    	echo "Sunrise: $sunrise.<br />Sunset: $sunset.<br />\n";
    	echo "</td><td><?php include('weather_insert.php'); ?></td></tr></table></p>";
    
    $color_bar = <<< end_of_output
    <table border="1" cellspacing="0" cellpadding="4" style="border-collapse: collapse" bordercolor="#000000">
      <tr>
        <td width="9%" bgcolor="#CC99CC" align="center">
        <font face="arial" size="1">&lt;10</font></td>
        <td width="9%" bgcolor="#9966FF" align="center">
        <font face="arial" size="1">10's</font></td>
        <td width="9%" bgcolor="#3399FF" align="center">
        <font face="arial" size="1">20's</font></td>
        <td width="9%" bgcolor="#99CCFF" align="center">
        <font face="arial" size="1">30's</font></td>
        <td width="9%" bgcolor="#66CC66" align="center">
        <font face="arial" size="1">40's</font></td>
        <td width="9%" bgcolor="#FFFF99" align="center">
        <font face="arial" size="1">50's</font></td>
        <td width="9%" bgcolor="#FFCC33" align="center">
        <font face="arial" size="1">60's</font></td>
        <td width="9%" bgcolor="#FF9933" align="center">
        <font face="arial" size="1">70's</font></td>
        <td width="9%" bgcolor="#FF6600" align="center">
        <font face="arial" size="1">80's</font></td>
        <td width="9%" bgcolor="#FF0000" align="center">
        <font face="arial" size="1">90's</font></td>
        <td width="10%" bgcolor="#990000" align="center">
        <font face="arial" size="1" color="#FFFFFF">100+</font></td>
      </tr>
    </table>
    end_of_output;
    echo $color_bar;
    Con't in next post

  4. #24
    Join Date
    Feb 2005
    Location
    Flagstaff, Arizona, United States
    Age
    42
    Posts
    27

    Default

    Code:
    	echo "<table border=\"0\" cellpadding=\"4\" cellspacing=\"1\" bgcolor=\"#C0C0C0\"><tr><th>Date</th><th>High/Low</th><th>Day</th><th>Night</th></tr>";
    	foreach ($index[day] as $day)
    	{
    		if ($values[$day][attributes][t] != "")
    		{
    //			($row_counter%2==0) ? $row_color =  "#CCE6FF": $row_color = "#CCCDFF";
    			$row_color = "#1A1818";
    			$img_day = (($counter + 1) * 2) - 1;
    			$img_night = ($counter + 1) * 2;
    
    			$day_text = (($counter + 1) * 3) + $counter;
    			$day_wind = ((($counter + 1) * 3) + $counter) + 1;
    			$day_windspeed = (($counter + 1) * 2) - 1;
    			$day_windgust = (($counter + 1) * 2) - 1;
    			$day_humidity = (($counter + 1) * 2) - 1;
    			$day_precip = $counter * 2;
    
    			$night_text = ((($counter + 1) * 3) + $counter) + 2;
    			$night_wind = ((($counter + 1) * 3) + $counter) + 3;
    			$night_windspeed = ($counter + 1) * 2;
    			$night_windgust = ($counter + 1) * 2;
    			$night_humidity = ($counter + 1) * 2;
    			$night_precip = ($counter * 2) + 1;
    
    			if ($values[$index[hi][$counter]][value] >= 0) $heat_color = "#CC99CC";
    			if ($values[$index[hi][$counter]][value] >= 10) $heat_color = "#9966FF";
    			if ($values[$index[hi][$counter]][value] >= 20) $heat_color = "#3399FF";
    			if ($values[$index[hi][$counter]][value] >= 30) $heat_color = "#99CCFF";
    			if ($values[$index[hi][$counter]][value] >= 40) $heat_color = "#66CC66";
    			if ($values[$index[hi][$counter]][value] >= 50) $heat_color = "#FFFF99";
    			if ($values[$index[hi][$counter]][value] >= 60) $heat_color = "#FFCC33";
    			if ($values[$index[hi][$counter]][value] >= 70) $heat_color = "#FF9933";
    			if ($values[$index[hi][$counter]][value] >= 80) $heat_color = "#FF6600";
    			if ($values[$index[hi][$counter]][value] >= 90) $heat_color = "#FF0000";
    			if ($values[$index[hi][$counter]][value] >= 100) $heat_color = "#990000";
    			if ($values[$index[hi][$counter]][value] == "N/A") $heat_color = "#EEEECC";
    				
    			echo "<tr><td bgcolor=\"$heat_color\"><b>" . $values[$day][attributes][t] . ", " . $values[$day][attributes][dt] . "</b></td>";
    			echo "<td bgcolor=\"$row_color\"><b>Hi: " . $values[$index[hi][$counter]][value] . "˚ $unit_temp\n";
    			echo "<hr noshade height=\"1\">Lo: " . $values[$index[low][$counter]][value] . "˚ $unit_temp</b></td>\n";
    
    			echo "<td bgcolor=\"$row_color\" nowrap><table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"><tr><td><b>\n";
    			echo $values[$index[t][$day_text]][value] . "</b><br /> ";
    			echo "<font size=1>Sunrise: " . $values[$index[sunr][$counter]][value] . "<br />";
    			echo "Wind: " . $values[$index[t][$day_wind]][value] . " " . $values[$index[s][$day_windspeed]][value] . " $unit_speed";
    			echo "<br />Humidity: " . $values[$index[hmid][$day_humidity]][value] . "%<br />Precip: " . $values[$index[ppcp][$day_precip]][value] . "%</font></td>";
    			echo "<td bgcolor=\"$row_color\" align=\"right\"><img border=\"1\" src=\"/images/weather/$image_size/" . $values[$index[icon][$img_day]][value] . ".png\" alt=\"" . $values[$index[t][$day_text]][value] . "\"></td></tr></table></td>";
    
    			echo "<td bgcolor=\"$row_color\" nowrap><table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"><tr><td><b>\n";
    			echo $values[$index[t][$night_text]][value] . "</b><br />";
    			echo "<font size=1>Sunset: " . $values[$index[suns][$counter]][value] . "<br />";
    			echo "Wind: " . $values[$index[t][$night_wind]][value] . " " . $values[$index[s][$night_windspeed]][value] . " $unit_speed";
    			echo "<br />Humidity: " . $values[$index[hmid][$night_humidity]][value] . "%<br />Precip: " . $values[$index[ppcp][$night_precip]][value] . "%</font></td>\n";
    			echo "<td bgcolor=\"$row_color\" align=\"right\"><img border=\"1\" src=\"/images/weather/$image_size/" . $values[$index[icon][$img_night]][value] .".png\" alt=\"" . $values[$index[t][$night_text]][value] . "\"></tr></table></td>";
    			echo "</tr>";
    
    			$counter++;
    			$row_counter++;
    		}
    	}
    	echo "</table>";
    }
    
    if ($location And is_array($index[loc])) // A city name has been entered and data returned from weather.com, draw drop down menu of matches
    {
    
    	if (count($index[loc]) == 1) // If just one match returned, send to detail screen - no need to draw option box for one option.
    	{
    		$location_code = $values[$index[loc][0]][attributes][id];
    		header("Location: weather_xml.php?id=$location_code&length=10"); // Nees html_header because of this redirect.
    		exit();
    	}
    
    	html_header();
    
    	echo "<form action=\"weather_xml.php\" method=\"POST\">";
    	echo "Select a city: <select size=\"1\" name=\"id\">\n";
    	// Loop through the XML, setting values
    	foreach ($index[loc] as $key=>$val)
    	{
    		echo "<option value=\"";
    		echo $values[$val][attributes][id]; // City code
    		echo "\">";
    		echo $values[$val][value]; // City name
    		echo "</option>\n";
    	}
    	echo '</select>';
    ?>
    
    Length of forecast 
    <select size="1" name="length">
    <option selected>10</option>
    <option>9</option>
    <option>8</option>
    <option>7</option>
    <option>6</option>
    <option>5</option>
    <option>4</option>
    <option>3</option>
    <option>2</option>
    <option>1</option>
    </select>
    <input type="submit" value="Get Weather">
    </form>
    <?
    
    }
    elseif ($location) // City or zip entered but no match returned from weather.com
    {
    	html_header();
    	echo "No city found. Please enter another city or zip code.<br />\n";
    }
    
    if (empty($location) And empty($loc_id))
    {
    	html_header();
    }
    ?></body></html

  5. #25
    Join Date
    Feb 2005
    Location
    Flagstaff, Arizona, United States
    Age
    42
    Posts
    27

    Default

    Still having problems. I'm guessing weather.com changed something on their end as the site in the first post seems to be screwy just like mine.

    It appears as though the variables that are set with this mod, day_text and day_wind are flip flopped, night are the same. Plus the numbers be read into for the images are either slightly or just sometimes off. I changed some variables so it looks better. I flipped the images from day to night, and the text/wind direction so that is better.

    Any ideas of what happened here?
    My page is at http://cosmorealtor.com/weather.php

  6. #26
    Join Date
    Jan 2005
    Location
    Phoenix, AZ
    Age
    59
    Posts
    14

    Thumbs up Fonts

    WWOBN...thanks a lot - instructions were great. The only thing I did was delete the following from the weather_xml.php file as it changed my fonts:

    <style>
    <!--
    body, p { font-size: 10pt; font-family: Verdana }
    td { font-size: 10pt; font-family: Verdana }
    -->
    </style>

  7. #27
    Join Date
    Mar 2005
    Posts
    4

    Default

    I just tried installing the script and get this error

    Warning: Invalid argument supplied for foreach() in /home3/www/cue1/weather_xml.php on line 200

    Line 200 is
    foreach ($index[day] as $day)


    link:
    http://www.cue1.net/weather.php

    Any ideas?
    Thanks
    -Harris

  8. #28
    Join Date
    Mar 2005
    Posts
    4

    Default

    Does anybody have any ideas on what is causing this and how to fix it?

    Just for fun I deleted "[day]" and the error message went away but all the fields were blank.

    Thanks in advance.
    -Harris

  9. #29
    Join Date
    Jan 2005
    Location
    Phoenix, AZ
    Age
    59
    Posts
    14

    Default PHP problems ??

    Harris...didn't have much time to look at this but from a quick glance it seems to be an issue with PHP. I'm wondering if the 'day' variable is somehow not being populated - possible PHP version issue ??
    I'm running 4.3.10 with no problems.
    Just a thougt...Bill

  10. #30
    Join Date
    Jan 2005
    Location
    Phoenix, AZ
    Age
    59
    Posts
    14

    Default take that back

    Harris...got a some time to look a little closer. My last posting indicated there may be a 'day' function that wasn't being populated but there is no such animal in PHP, it was the 'date' function I was thinking about.
    Reson I thought it was a built-in PHP function was I didn't see it being declared anywhere, my fault for not having time.
    After a closer look you'll see under the 'Set tag names and values' the statement 'xml_parse_into_struct($parser,$xml,$values,$index ); '
    This is where it is parsing the XML into an array structure.
    (you'll see this line twice as it is part of an 'if' statement where it checks to see how old the db info is)
    go down to where you see '//print_r($values);' (my line 129) and take off the '//' to uncomment it. Save it and go to your webpage and click on the weather link. If it is parsing correctly you should see something like this:
    ----------------------------------------------------------------------
    Array ( [0] => Array ( [tag] => weather [type] => open [level] => 1 [attributes] => Array ( [ver] => 2.0 ) [value] => ) [1] => Array ( [tag] => head [type] => open [level] => 2 [value] => ) [2] => Array ( [tag] => locale [type] => complete [level] => 3 [value] => en_US ) [3] => Array ( [tag] => head [value] => [type] => cdata ............
    ----------------------------------------------------------------------
    If not there is probably a good chance there is something wrong with the communication with Weather.com. Double check all the setup instructions for your account with them. Not sure what else to say...Bill

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •