Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Send to multiple weather widgets from a single job
require 'net/http'
require 'xmlsimple'
# Get a WOEID (Where On Earth ID)
# for your location from here:
woe_ids = {"weather-ottawa" => 3369, "weather-toronto" => 123, "weather-montreal" => 456}
# Temerature format:
# 'c' for Celcius
# 'f' for Fahrenheit
format = 'c'
SCHEDULER.every '15m', :first_in => 0 do |job|
woe_ids.each do |widget_name, woe_id|
update_weather widget_name, woe_id
def update_weather(widget_name, woe_id)
http ='')
response = http.request("/forecastrss?w=#{woe_id}&u=#{format}"))
weather_data = XmlSimple.xml_in(response.body, { 'ForceArray' => false })['channel']['item']['condition']
send_event(widget_name, { :temp => "#{weather_data['temp']}°#{format.upcase}", :condition => weather_data['text'] })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment