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_array = [12770217,12770218,12770219]
- # 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')
- woe_id_array.each do |woe_id|
- 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'] })
- sleep(15)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement