Need help adding local weather feed to my site

  • Realty
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Mozambique & Bahamas

Post 3+ Months Ago

Hello webmasters,

I have a website and I would like to add local weather but I have no idea how to do it.

I could use the codding from weather.com and place it in one of my pages, but it shows too many information.

So after a lot of search I found that I could also use the weather feed from yahoo: Yahoo! Weather - Yahoo! Developer Network

I was able to follow their instructions and I now have the code below:


Code: [ Select ]
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://weather.yahooapis.com/ns/rss/1.0"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - Nassau, NP</title>
<link>http://us.rd.yahoo.com/dailynews/rss...er/Nassau__BF/
*http://weather.yahoo.com/forecast/94089_f.html</link>
<description>Yahoo! Weather for Nassau, NP</description>
<language>en-us</language>
<lastBuildDate>Tue, 29 Nov 2005 3:56 pm PST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Nassau" region="NP" country="BS"></yweather:location>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"></yweather:units>
<yweather:wind chill="57" direction="350" speed="7"></yweather:wind>
<yweather:atmosphere humidity="93" visibility="1609" pressure="30.12" rising="0"></yweather:atmosphere>
<yweather:astronomy sunrise="7:02 am" sunset="4:51 pm"></yweather:astronomy>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com/</link>
<url>http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Nassau, NP at 3:56 pm PST</title>
<geo:lat>37.39</geo:lat>
<geo:long>-122.03</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/
<span style="font-size: 0px"> </span>Nassau__BF/*
<span style="font-size: 0px"> </span>http://weather.yahoo.com/<span style="font-size: 0px"> </span>forecast/BFXX0005_f.html
</link>
<pubDate>Tue, 29 Nov 2005 3:56 pm PST</pubDate>
<yweather:condition text="Mostly Cloudy" code="26" temp="57" date="Tue, 29 Nov 2005 3:56
pm PST"></yweather:condition>
<description><![CDATA[
<img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/26.gif" /><br />
<b>Current Conditions:</b><br />
Mostly Cloudy, 57 F<p />
<b>Forecast:</b><BR />
Tue - Mostly Cloudy. High: 62 Low: 45<br />
Wed - Mostly Cloudy. High: 60 Low: 52<br />
Thu - Rain. High: 61 Low: 46<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Nassau__BF/*http://weather.yahoo.com/forecast/BFXX0005_f.html">Full Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>]]>
</description>
<yweather:forecast day="Tue" date="29 Nov 2005" low="45" high="62" text="Mostly Cloudy"
code="27"></yweather:forecast>
<yweather:forecast day="Wed" date="30 Nov 2005" low="52" high="60" text="Mostly Cloudy"
code="28"></yweather:forecast>
<guid isPermaLink="false">94089_2005_11_29_15_56_PST</guid>
</item>
</channel>
</rss>
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2. <rss version="2.0" xmlns:yweather="http://weather.yahooapis.com/ns/rss/1.0"
  3. xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  4. <channel>
  5. <title>Yahoo! Weather - Nassau, NP</title>
  6. <link>http://us.rd.yahoo.com/dailynews/rss...er/Nassau__BF/
  7. *http://weather.yahoo.com/forecast/94089_f.html</link>
  8. <description>Yahoo! Weather for Nassau, NP</description>
  9. <language>en-us</language>
  10. <lastBuildDate>Tue, 29 Nov 2005 3:56 pm PST</lastBuildDate>
  11. <ttl>60</ttl>
  12. <yweather:location city="Nassau" region="NP" country="BS"></yweather:location>
  13. <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"></yweather:units>
  14. <yweather:wind chill="57" direction="350" speed="7"></yweather:wind>
  15. <yweather:atmosphere humidity="93" visibility="1609" pressure="30.12" rising="0"></yweather:atmosphere>
  16. <yweather:astronomy sunrise="7:02 am" sunset="4:51 pm"></yweather:astronomy>
  17. <image>
  18. <title>Yahoo! Weather</title>
  19. <width>142</width>
  20. <height>18</height>
  21. <link>http://weather.yahoo.com/</link>
  22. <url>http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
  23. </image>
  24. <item>
  25. <title>Conditions for Nassau, NP at 3:56 pm PST</title>
  26. <geo:lat>37.39</geo:lat>
  27. <geo:long>-122.03</geo:long>
  28. <link>http://us.rd.yahoo.com/dailynews/rss/weather/
  29. <span style="font-size: 0px"> </span>Nassau__BF/*
  30. <span style="font-size: 0px"> </span>http://weather.yahoo.com/<span style="font-size: 0px"> </span>forecast/BFXX0005_f.html
  31. </link>
  32. <pubDate>Tue, 29 Nov 2005 3:56 pm PST</pubDate>
  33. <yweather:condition text="Mostly Cloudy" code="26" temp="57" date="Tue, 29 Nov 2005 3:56
  34. pm PST"></yweather:condition>
  35. <description><![CDATA[
  36. <img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/26.gif" /><br />
  37. <b>Current Conditions:</b><br />
  38. Mostly Cloudy, 57 F<p />
  39. <b>Forecast:</b><BR />
  40. Tue - Mostly Cloudy. High: 62 Low: 45<br />
  41. Wed - Mostly Cloudy. High: 60 Low: 52<br />
  42. Thu - Rain. High: 61 Low: 46<br />
  43. <br />
  44. <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Nassau__BF/*http://weather.yahoo.com/forecast/BFXX0005_f.html">Full Forecast at Yahoo! Weather</a><BR/>
  45. (provided by The Weather Channel)<br/>]]>
  46. </description>
  47. <yweather:forecast day="Tue" date="29 Nov 2005" low="45" high="62" text="Mostly Cloudy"
  48. code="27"></yweather:forecast>
  49. <yweather:forecast day="Wed" date="30 Nov 2005" low="52" high="60" text="Mostly Cloudy"
  50. code="28"></yweather:forecast>
  51. <guid isPermaLink="false">94089_2005_11_29_15_56_PST</guid>
  52. </item>
  53. </channel>
  54. </rss>

Can somebody tell me how to use that code so I can display weather on my site in rss feed format?

I am new in designing sites, please help.

Regards,
Realty
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

You need an RSS Parser. If you're using PHP, you can check out Magpie ... http://magpierss.sourceforge.net/
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

  • Realty
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Mozambique & Bahamas

Post 3+ Months Ago

righteous_trespasser wrote:


Hello there,

Thanks for the tutorial.
As I was saying in my first post, I am new with codes and I would like to learn more.

In your tutorial, you have first explained in xml and then in php, and you have also shown the feed for your location.

I already have my feed: http://weather.yahooapis.com/forecastrss?p=BFXX0005&u=f and would like to prepare my page (index.html) and be able to read that feed.

My questions are ( I know it may sound stupid, but I need to understand better)
1) Do I have to save those codes in separate, say: xyz.xml and xyz.php and then upload them to my server where my index page is located?

2) What code/line should I use to place on my page (index.html)?
Below is one of the examples I am talking about.
http://www.mariocareyrealty.com/index.php

Thanks in advance.
Realty
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Realty wrote:
1) Do I have to save those codes in separate, say: xyz.xml and xyz.php and then upload them to my server where my index page is located?

The XML you would get from the yahoo page, this page is the XML ...
Realty wrote:
2) What code/line should I use to place on my page (index.html)?

In my tutorial, you can place this PHP below where you want the weather to show ... you can take out the quotes ... also the index page will be named index.php and not index.html ...
Code: [ Select ]
<?php
//I am using the DOM(Document Object Model) library to read the entire XML document into memory first.
$doc = new DOMDocument();
$doc->load('http://weather.yahooapis.com/forecastrss?p=SFXX0044&u=c');
//now I get all elements inside this document with the following name "channel", this is the 'root'
$channel = $doc->getElementsByTagName("channel");
//now I go through each item withing $channel
foreach($channel as $chnl)
{
//I then find the 'item' element inside that loop
$item = $chnl->getElementsByTagName("item");
foreach($item as $itemgotten)
{
//now I search within '$item' for the element "description"
$describe = $itemgotten->getElementsByTagName("description");
//once I find it I create a variable named "$description" and assign the value of the Element to it
$description = $describe->item(0)->nodeValue;
//and display it on-screen
echo $description;
}
}
?>
  1. <?php
  2. //I am using the DOM(Document Object Model) library to read the entire XML document into memory first.
  3. $doc = new DOMDocument();
  4. $doc->load('http://weather.yahooapis.com/forecastrss?p=SFXX0044&u=c');
  5. //now I get all elements inside this document with the following name "channel", this is the 'root'
  6. $channel = $doc->getElementsByTagName("channel");
  7. //now I go through each item withing $channel
  8. foreach($channel as $chnl)
  9. {
  10. //I then find the 'item' element inside that loop
  11. $item = $chnl->getElementsByTagName("item");
  12. foreach($item as $itemgotten)
  13. {
  14. //now I search within '$item' for the element "description"
  15. $describe = $itemgotten->getElementsByTagName("description");
  16. //once I find it I create a variable named "$description" and assign the value of the Element to it
  17. $description = $describe->item(0)->nodeValue;
  18. //and display it on-screen
  19. echo $description;
  20. }
  21. }
  22. ?>
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

Doh! I forgot your wrote the tut r_t. My bad. :)
  • Realty
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Mozambique & Bahamas

Post 3+ Months Ago

Hello righteous_trespasser,

Thanks.
Now I see why was not working.
The weather codes are in php and my sites are in html.

I will try to find another way.
Thanks for your help.

Realty
  • Realty
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Mozambique & Bahamas

Post 3+ Months Ago

digitalMedia wrote:
You need an RSS Parser. If you're using PHP, you can check out Magpie ... http://magpierss.sourceforge.net/


Hello DigitalMedia,

Thanks for the link you have provided.
The site I wanted to use the weather is in html.

Thanks again,
Realty
  • ph81luc
  • Born
  • Born
  • ph81luc
  • Posts: 3

Post 3+ Months Ago

Hi,

thanks for your code; I have applied it and receive the following error:
Catchable fatal error: Object of class DOMNodeList could not be converted to string in /home/a2163261/public_html/weather.php on line 12

do you know from where this can come from?

Thanks!

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 73 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.