Created
June 30, 2015 18:30
-
-
Save mapledyne/4d3e417f2fef2d1ab83d to your computer and use it in GitHub Desktop.
Local bus info widget in Dashing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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