Advertisement
scubes13

Dashing Weather Widget - With Location

Feb 26th, 2013
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement