Yweather
Overview
This is a rewrite of Walter Korman's [email protected] yahoo-weather gem.
The aim of this port/rewrite is to add proper specs, better test-coverage and active maintenance. I have ported much of Walter's original intent and LICENSE, and thank him for his contribution. My initial motivation is to send Prowl notifications to my iPad, iPhone, iPod whenever hazardous weather is coming.
Yweather provides an object-oriented Ruby interface to the Yahoo! Weather XML RSS feed detailed at http://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.
Source code is at http://github.com/midwire/yweather.
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:
http://developer.yahoo.com/weather/archive.html
Installation
gem install yweather
Usage
A simple example program:
#!/usr/bin/env ruby
require "yweather"
require "colorize"
zipcode = ARGV.shift
if zipcode.nil?
puts ">>> Usage: yweather zipcode"
exit
end
client = Yweather::Client.new
response = client.get_response_for_zipcode(zipcode)
# TODO: Use a ~/.yweather YAML file to determine format of output
print <<edoc
#{response.title.yellow}
#{response.condition.temp} degrees
#{response.condition.text}
edoc
puts "Wind:".yellow
response.wind_conditions.each_pair do |key, value|
puts " #{key}: #{value}"
end
puts "Atmosphere:".yellow
response.atmospheric_conditions.each_pair do |key, value|
puts " #{key}: #{value}"
end
Produces output as:
Conditions for Beverly Hills, CA at 10:51 am PST
61 degrees
Fair
Wind:
chill: 61°
direction: 0°
speed: 0 mph
Atmosphere:
humidity: 23%
visibility: 10 mi
pressure: steady at 30.18in
There is a variety of detailed weather information in other attributes of the Yweather::Response object.
License
This library is provided via the GNU LGPL license at http://www.gnu.org/licenses/lgpl.html.
Author
Copyright 2006 - 2009, Walter Korman [email protected], http://lemurware.blogspot.com.
Copyright 2012, Chris Blackburn
Thanks to Walter Korman for the initial hack.
Notes
Pull requests are appreciated. Please use feature/branches or hotfix/branches and add specs for your changes.
ToDo
- Use a ~/.yweather YAML file, or some other templating scheme, to determine format of output when running the binary.