Fetching contributors…
Cannot retrieve contributors at this time
103 lines (75 sloc) 3.26 KB



yahoo-weather provides an object-oriented interface to the Yahoo! Weather XML RSS feed detailed at

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

Source code is at

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:

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

Then install the gem by executing:

% gem install yahoo-weather


A simple example program:

require 'rubygems'
require 'yahoo-weather'

@client =
# look up WOEID via; 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.condition.temp} degrees

# sample html output
print <<edoc
  <img src="#{response.image.url}"><br/>
  #{response.condition.temp} degrees #{response.units.temperature}<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>.

Produces output as:

Conditions for Santa Monica, CA at 10:51 am PST
56 degrees
Partly Cloudy
  <img src=""><br/>
  56 degrees F<br/>
  Partly Cloudy<br>
  Sat - Mostly Cloudy.  High: 59 Low: 46<br/>
  Sun - Partly Cloudy.  High: 64 Low: 48<br/>
  More information <a href="*">here</a>.

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


Copyright 2006 - 2009, Walter Korman <>,

Thanks to Matthew Berk for inspiration and initial hack.