Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Dashing Weather Widget - With Location

By: scubes13 on Feb 26th, 2013  |  syntax: None  |  size: 0.78 KB  |  views: 307  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'net/http'
  2. require 'xmlsimple'
  3.  
  4. # Get a WOEID (Where On Earth ID)
  5. # for your location from here:
  6. # http://woeid.rosselliot.co.nz/
  7. woe_id = 12770218
  8.  
  9. # Temerature format:
  10. # 'c' for Celcius
  11. # 'f' for Fahrenheit
  12. format = 'f'
  13.  
  14. SCHEDULER.every '15m', :first_in => 0 do |job|
  15.   http = Net::HTTP.new('weather.yahooapis.com')
  16.   response = http.request(Net::HTTP::Get.new("/forecastrss?w=#{woe_id}&u=#{format}"))
  17.   weather_data = XmlSimple.xml_in(response.body, { 'ForceArray' => false })['channel']['item']['condition']
  18.   weather_city = XmlSimple.xml_in(response.body, { 'ForceArray' => false })['channel']['location']
  19.   send_event('weather', { :temp => "#{weather_data['temp']}°#{format.upcase}", :condition => weather_data['text'], :title => weather_city['city'] })
  20. end
clone this paste RAW Paste Data