Created
October 7, 2014 23:34
-
-
Save dmerrick/cacd86ab16aafafa9a20 to your computer and use it in GitHub Desktop.
Let me know when the DMV line is short!
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 | |
# this script will scrape the CA DMV website for wait times, | |
# and if the wait is less than a certain threshold, it will | |
# alert you with an audible message (at least on OS X). | |
require 'open-uri' | |
require 'date' | |
# found from http://apps.dmv.ca.gov/web/fieldoffice.html?number=503 | |
@branch_id = 503 | |
@branch_name = 'San Francisco' | |
@url = 'http://apps.dmv.ca.gov/fodata/Output2.txt' | |
@alert_threshold = 10 # minutes | |
# fetch the latest wait times | |
# returns an array of [hours,minutes] | |
def fetch_wait_time | |
data = open(@url).grep(/^#{@branch_id}/).first | |
data.split(',').slice(1..-1) | |
end | |
# this gets called if the wait time is below a certain threshold | |
# (you could change it to send an email or anything you like) | |
def alert | |
system("say 'DMV line is less than #{@alert_threshold} minutes long'") | |
end | |
loop do | |
puts "🚙 " + DateTime.now.strftime('%D %I:%M%p') | |
# pull down the wait time from the DMV website | |
hours, minutes = fetch_wait_time | |
puts "🏫 current wait time for #{@branch_name} office is #{hours}:#{minutes.rjust(2,'0')}" | |
alert if hours.to_i < 1 && minutes.to_i < @alert_threshold | |
puts "💤 sleeping for 5 minutes" | |
sleep 5*60 | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment