Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: YAHOO_WEATHER_…
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 89 lines (63 sloc) 2.708 kb

yahoo-weather

About

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, which sometimes seems ironic given that they can just glance out the window, but we can all understand the 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 is at rubyforge.org/projects/yahoo-weather.

Source code is at github.com/shaper/yahoo-weather.

Installation

Install rubygems if you don't already have it. See rubyforge.org/projects/rubygems/.

Then install the gem by executing:

% gem install yahoo-weather

Usage

A simple example program:

require 'rubygems'
require 'yahoo-weather'

@client = YahooWeather::Client.new
response = @client.lookup_location('98103')

# 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 Seattle, WA at 2:53 pm PST
55 degrees F
Light Rain
<div>
  <img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/11.gif"><br/>
  55 degrees F<br/>
  Light Rain<br>
  Forecast:<br/>
  Sun - Rain/Wind.  High: 56 Low: 54<br/>
  Mon - Heavy Rain/Wind.  High: 60 Low: 54<br/>
  More information <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Seattle__WA/*http://xml.weather.yahoo.com/forecast/98103_f.html">here</a>.
</div>

There is a variety of detailed weather information in other attributes of the YahooWeather::Response object.

License

This library is provided via the GNU LGPL license at www.gnu.org/licenses/lgpl.html.

Author

Copyright 2006 - 2009, Walter Korman <shaper@fatgoose.com>, lemurware.blogspot.com.

Thanks to Matthew Berk for inspiration and initial hack.

Something went wrong with that request. Please try again.