Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/http'
- require 'xmlsimple'
- # Get a WOEID (Where On Earth ID)
- # for your location from here:
- # http://woeid.rosselliot.co.nz/
- woe_id = 12770218
- # Temerature format:
- # 'c' for Celcius
- # 'f' for Fahrenheit
- format = 'f'
- SCHEDULER.every '15m', :first_in => 0 do |job|
- http = Net::HTTP.new('weather.yahooapis.com')
- response = http.request(Net::HTTP::Get.new("/forecastrss?w=#{woe_id}&u=#{format}"))
- weather_data = XmlSimple.xml_in(response.body, { 'ForceArray' => false })['channel']['item']['condition']
- weather_city = XmlSimple.xml_in(response.body, { 'ForceArray' => false })['channel']['location']
- send_event('weather', { :temp => "#{weather_data['temp']}°#{format.upcase}", :condition => weather_data['text'], :title => weather_city['city'] })
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement