scubes13

Dashing Weather Widget - With Location

Feb 26th, 2013
640
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×