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 ↓
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?
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
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’)
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.
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
Hi capitan,
you could just use the regular strftime function to format time and dates:
http://apidock.com/ruby/Time/strftime
Leave a Comment