RWeather: Check your local weather using ruby

Well, I have to say that the main motivation to write this gem was just to write a gem. I’ve never done it before. That being said, here’s rweather with you.

What does it do ?

It’s a ruby wrapper for the Weather XML Data Feed from weather.com.

It currently has two features, searching locations to get their location_id and getting the weather current conditions for a given location.

Getting the code and Installing

The rweather code is of course available at github and is released with a MIT license.

To install it just do the usual:
sudo gem install ckozus-rweather --source http://gems.github.com

How to Use It

This is a simple script using rweather taken from the README. It gets a list of matching locations and shows the current temperature and what it feels like.

6 comments ↓

#1 Amaiko on 09.18.08 at 12:28 pm

That’s cool … Thank you for this gem
I modified the code above little bit for using it at my pc

require ‘rubygems’
require ‘r_weather’
RWeather.partner_id =”1075408907″ # Use Your Own Please
RWeather.key = “64af5eed14c14004″ # Use Your Own Plase
print “Enter Your City - (Cairo, Egypt) : “;cy = gets.chomp
locations = RWeather.search(cy)
unless locations.empty?
locations.each_with_index do |location, i|
puts “#{i}) #{location.id} - #{location.name}”
end
cc = RWeather.current_conditions(locations.first.id)
ct = (cc.tmp.to_i - 32) * 0.56
cf = (cc.flik.to_i - 32) * 0.56
puts “Current conditions: ”
puts ” Temperature: #{ct.to_i} C”
puts ” Feels like: #{cf.to_i} C”
end

but what about showing the wind speed
how can i do it?

#2 Amaiko on 09.18.08 at 6:36 pm

I knew how :)

require ‘rubygems’
require ‘r_weather’

RWeather.partner_id =”1075408907″ # Use Your Own Please
RWeather.key = “64af5eed14c14004″ # Use Your Own Please
print “Enter Your City - (Cairo, Egypt) : “;cy = gets.chomp
locations = RWeather.search(cy)
unless locations.empty?
locations.each_with_index do |location, i|
puts “#{i}) #{location.id} - #{location.name}”
end
cc = RWeather.current_conditions(locations.first.id)
ct = (cc.tmp.to_i - 32) * 0.56
cf = (cc.flik.to_i - 32) * 0.56
cw = cc.wind.s.to_f * 1.61
puts “Current conditions for #{cc.obst} ”
puts “It’s #{cc.lsup}”
puts ” Temperature: #{ct.to_i} C”
puts ” Feels like: #{cf.to_i} C”
puts ” Wind Speed : #{cw} km/h”
end

#3 ckozus on 09.19.08 at 12:59 am

That’s right :)

Also, you can pass an extra parameter to RWeather.current_conditions to get data using metric units so you dont have to handle the convertions yourself.

cc = RWeather.current_conditions(locations.first.id, ‘m’)

#4 Daniel on 11.23.08 at 12:20 pm

Hi! This is a great tutorial. Anyways, is there anyway you could explain this on Ruby on Rails? I want to develop a web-app on RoR with a weather forecast function.

#5 capitan on 07.20.09 at 1:49 pm

Great! that’s what i need, is there a way to format the date in a different way, in my country we speak spanish, the date is in this way “dd/mm/YYYY”. And is there a way to use the icons provided by weather to show the differents weather, sunny, cloudy, etc.

thanks in advance, your work is great

#6 ckozus on 07.21.09 at 11:38 am

Hi capitan,

you could just use the regular strftime function to format time and dates:

http://apidock.com/ruby/Time/strftime

Leave a Comment