By MarekP on
Weather forecast snippet
I've tried a couple of weather modules, but none of them seems to work properly. That's why I've turned to MSN Weather RSS feeds and used built in Aggregator module for my Corsica weather page. Here is how to do it:
1) Turn the Aggregator module on.
2) Select a RSS feed from MSN Weather and subscribe to it.
3) Enable Cron or at least the Poormanscron module.
4) Put the following PHP snippet in the page, where you want to show the current weather conditions and the 5-day weather forecast:
// Show Current conditions
$output = '';
$result = db_query("
SELECT a.*
FROM {aggregator_item} a
WHERE (a.fid=1) AND (a.title LIKE '%Current Conditions%')
ORDER BY a.timestamp DESC, iid DESC
LIMIT 1
");
while ($item = db_fetch_object($result)) {
$output .= '<h2>' . check_plain($item->title) . '</h2>';
if ($item->description) {
$output .= '<div>'. aggregator_filter_xss($item->description) . "</div>\n";
}
}
print $output;
// Show 5-day weather forecast
$output = '';
$result = db_query("
SELECT a.*
FROM {aggregator_item} a
WHERE (a.fid=1) AND (a.title LIKE '%Forecast%')
ORDER BY a.timestamp DESC, iid DESC
LIMIT 1
");
while ($item = db_fetch_object($result)) {
$output .= '<h2>' . check_plain($item->title) . '</h2>';
if ($item->description) {
$output .= '<div>'. aggregator_filter_xss($item->description) . "</div>\n";
}
}
print $output;
Because I'm not a PHP guru, your suggestions and improvements are welcome. If someone can make a module from the snippet, it would be great.
Comments
Do you have a live example
Do you have a live example of this anywhere ? I'm very interested ...
--
http://www.porttalbotchat.co.uk
-------------------------------------------------
Our mission is to discuss issues and topics of residents of Port Talbot. We provide info on events, issues, concerns and discussions of our local area.
Live example
Yes, a live example is here: http://corsica.forhikers.com/weather
OK this looks great. I
OK this looks great. I assujme however you only have this feed and no others in aggregator, how would you adapt this to work with multiple feeds, one being the weather ?
The feed i'm hoping to do the same with is http://weather.msn.com/RSS.aspx?wealocations=wc:UKXX0114&weadegreetype=F
I assume i subscribe to that via the aggregator feeds then run your code but will need to select just that feed correct ?
Any help appreciated.
--
http://www.porttalbotchat.co.uk
-------------------------------------------------
Our mission is to discuss issues and topics of residents of Port Talbot. We provide info on events, issues, concerns and discussions of our local area.
fid
In the following piece of code:
replace 1 with the proper id of your feed.
Thanks very much, seems to
Thanks very much, seems to work. One thing i don;t quite understand is how you get the images to show up ? For the weather conditions ? They seem to be in the RSS but are not displaying, any ideas ?
Thanks again.
--
http://www.porttalbotchat.co.uk
-------------------------------------------------
Our mission is to discuss issues and topics of residents of Port Talbot. We provide info on events, issues, concerns and discussions of our local area.
Enable img tag in the Aggregator setup
Go to administer » settings » Aggregator and add the img tag in the list of allowed HTML tags.
Feed ID
This may seem obvious, but what number do you place in here for the feed ID? On your Corsican weather feed, for example, do you put in "wc:UKXX0114" or "UKXX0114" or just "0114".
I got errors with the first two, and a blank page with the last one, even though cron has updated.
Thanks!
thanks for sharing this snippet - works well...
strip out some of the msn rss weather feed
anyone have code to strip out and remove the links at the bottom like: Detailed ten-day forecast Hourly Weather Forecast Weather maps Weather Averages
? i guess i should read up on how to parse the news aggregator?
Any way to add a weather block?
I just tried this and it works great, but I'd also like to have one of those tiny little weather blocks that just shows a graphic and the temperature and have that link to this weather page I created. Any suggestions?
Thanks,
Michelle
--------------------------------------
My site: http://shellmultimedia.com
No RSS feed displays on the page
I followed the instructions here and nothing comes up. Here's what I did:
1. Turned Aggregator module on and assigned permissions
2. Subscribed (copied) the following link from the MSN Weather site: http://weather.msn.com/RSS.aspx?wealocations=wc:ASXX0112&weadegreetype=F
3. Created a new page node in Drupal and pasted the PHP code per above and enabling the PHP Code Input Format when creating the page node
4. Cron is enabled
5. Added a feed (per the link in step 2) within the News Aggregator module setup
The page is blank - nothing happens.
If anyone has any ideas, I'd appreciate it!
I haven't worked with RSS feeds in Drupal previous to this but I believe I followed the instructions by MarekP to the letter??
Tim
Drupal 5.5
Oh, silly me...
The cron hadn't updated....I logged out and back in again and voila!
:-)
Thank You
This is to thank you for sharing your code with us. Appreciate your goodness. Thanks again
However, just wondering if this is legal. Does MSN allow its rss feeds to be republished even with proper attribution and link back to them?
Is it possible to put this
Is it possible to put this in feedapi? Greetings, Martijn
I think this module might
I think this module might help http://drupal.org/project/weather .