SHOW:
|
|
- or go back to the newest paste.
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_array = [12770217,12770218,12770219] | |
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 | woe_id_array.each do |woe_id| | |
17 | response = http.request(Net::HTTP::Get.new("/forecastrss?w=#{woe_id}&u=#{format}")) | |
18 | weather_data = XmlSimple.xml_in(response.body, { | |
19 | 'ForceArray' => false })['channel']['item']['condition'] | |
20 | weather_city = XmlSimple.xml_in(response.body, { | |
21 | 'ForceArray' => false })['channel']['location'] | |
22 | send_event('weather', { | |
23 | :temp => "#{weather_data['temp']}°#{format.upcase}", | |
24 | :condition => weather_data['text'], | |
25 | :title => weather_city['city'] }) | |
26 | sleep(15) | |
27 | end | |
28 | end |