Skip to content

Instantly share code, notes, and snippets.

@mapledyne
Created June 30, 2015 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mapledyne/4d3e417f2fef2d1ab83d to your computer and use it in GitHub Desktop.
Save mapledyne/4d3e417f2fef2d1ab83d to your computer and use it in GitHub Desktop.
Local bus info widget in Dashing
require 'rubygems'
require 'nokogiri'
require 'open-uri'
widget = 'oba'
walktime = 5
SCHEDULER.every '1m' do
soonest = 20
oba = Nokogiri::HTML(open("http://pugetsound.onebusaway.org/where/sign/stop.action?id=1_18359"))
buses = oba.xpath("//td[contains(@class,'arrivalsStatusEntry')]/span/text()")
buses.each { |bus|
if bus.to_s == 'NOW'
next
end
b = bus.to_s.to_i - walktime
if b < 0
next
end
soonest = [soonest,b].min
}
puts "sending " + widget.to_s + " : " + soonest.to_s
send_event(widget.to_s, { value: soonest.to_i })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment