yahoo-weather provides an object-oriented interface to the Yahoo! Weather XML RSS feed detailed at developer.yahoo.com/weather.
People care a lot about the weather. This may seem ironic given they can just glance out the window. However, we can all understand a fascination with details and forecasting.
Log the weather information to your database! Graph it to your heart’s content! Write a widget that emails the weather to your cell phone every five minutes with a link to your friend’s PayPal account to deposit money if the weather’s sunny and you both bet that it would be rainy. And the fun doesn’t have to stop there.
The RubyForge project page for this library is at rubyforge.org/projects/yahoo-weather.
Source code is at github.com/shaper/yahoo-weather.
NOTE: This library was updated as of December 2009 to use a new WOEID-based lookup interface. Yahoo has deprecated the older non-WOEID-based lookup API. The archived page with the deprecated API details is at:
developer.yahoo.com/weather/archive.html
The older interface is still operational but users of this library should shift from using YahooWeather::Client::lookup_location to YahooWeather::Client::lookup_by_woeid.
Install rubygems
if you don’t already have it. See rubyforge.org/projects/rubygems/.
Then install the gem by executing:
% gem install yahoo-weather
A simple example program:
require 'rubygems' require 'yahoo-weather' @client = YahooWeather::Client.new # look up WOEID via http://weather.yahoo.com; enter location by city # name or zip and WOEID is at end of resulting page url. herein we use # the WOEID for Santa Monica, CA. response = @client.lookup_by_woeid(2488892) # straight text output print <<edoc #{response.title} #{response.condition.temp} degrees #{response.condition.text} edoc # sample html output print <<edoc <div> <img src="#{response.image.url}"><br/> #{response.condition.temp} degrees #{response.units.temperature}<br/> #{response.condition.text}<br> Forecast:<br/> #{response.forecasts[0].day} - #{response.forecasts[0].text}. High: #{response.forecasts[0].high} Low: #{response.forecasts[0].low}<br/> #{response.forecasts[1].day} - #{response.forecasts[1].text}. High: #{response.forecasts[1].high} Low: #{response.forecasts[1].low}<br/> More information <a href="#{response.page_url}">here</a>. </div> edoc
Produces output as:
Conditions for Santa Monica, CA at 10:51 am PST 56 degrees Partly Cloudy <div> <img src="http://l.yimg.com/a/i/us/nws/th/main_142b.gif"><br/> 56 degrees F<br/> Partly Cloudy<br> Forecast:<br/> Sat - Mostly Cloudy. High: 59 Low: 46<br/> Sun - Partly Cloudy. High: 64 Low: 48<br/> More information <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Santa_Monica__CA/*http://weather.yahoo.com/forecast/USCA1024_f.html">here</a>. </div>
There is a variety of detailed weather information in other attributes of the YahooWeather::Response object.
This library is provided via the GNU LGPL license at www.gnu.org/licenses/lgpl.html.
Copyright 2006 - 2009, Walter Korman <[email protected]>, lemurware.blogspot.com.
Thanks to Matthew Berk for inspiration and initial hack.