Created
March 11, 2014 18:40
-
-
Save aughban/9492259 to your computer and use it in GitHub Desktop.
hacky bus tracker code
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'json' | |
require 'terminal-notifier' | |
require 'open-uri' | |
require 'date' | |
today = Date.today | |
tomorrow = today+1 | |
five_pm = Time.local(today.year, today.month, today.day, 17, 0, 0) | |
nine_am = Time.local(tomorrow.year, tomorrow.month, tomorrow.day, 9, 0, 0) | |
range = Range.new(five_pm, nine_am) | |
if range.cover?(Time.now) | |
feed = JSON.parse(open('http://citymapper.com/api/1/departures?ids=490010178S').read) | |
buses = [] | |
feed['stops'][0]['services'].select{|x| x['headsign'] == 'Shadwell'}.each do |times| | |
times['live_departures_seconds'].each do |time| | |
buses << time/60 | |
end | |
end | |
there_are_buses = buses.sort.join ", " | |
TerminalNotifier.notify('There are buses in: %s minutes' % there_are_buses, :title=> 'Bus Tracker') | |
end | |
puts Time.now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment