Skip to content

Instantly share code, notes, and snippets.

@petermikitsh
Created January 1, 2014 22:06
Show Gist options
  • Save petermikitsh/8212004 to your computer and use it in GitHub Desktop.
Save petermikitsh/8212004 to your computer and use it in GitHub Desktop.
PA DMV License Exam E-mail Notifier
# Provide the approriate server, port, from, username, and password fields.
# Author: Peter Mikitsh
require 'net/smtp'
def send_email(to, opts={})
opts[:server] ||= '' # SMTP SERVER
opts[:port] ||= 587 # PORT: DEFAULT IS 587
opts[:from] ||= '' # 'FROM' E-MAIL FIELD
opts[:username] ||= '' # E-MAIL LOGIN
opts[:password] ||= '' # E-MAIL PASSWORD
opts[:from_alias] ||= 'Driver\'s License Test App'
opts[:subject] ||= "Appointment Available"
opts[:body] ||= "Info below:"
message_body = <<END_OF_EMAIL
From: #{opts[:from_alias]} <#{opts[:from]}>
To: <#{to}>
Subject: #{opts[:subject]}
#{opts[:body]}
END_OF_EMAIL
smtp = Net::SMTP.new(opts[:server], opts[:port])
smtp.enable_starttls_auto
smtp.start(opts[:server], opts[:username], opts[:password], :plain)
smtp.send_message(message_body, opts[:username], to)
end
# Note: You must fill in the Driver's License Number and Date of Birth!
# Doesn't work if you already hold a valid Driver's License.
# Author: Peter Mikitsh
require 'rubygems'
require 'mechanize'
require_relative 'email'
agent = Mechanize.new
def login(agent)
# Load initial page
page = agent.get('https://www.dot33.state.pa.us/exam_scheduling/eslogin.jsp?navigation=true')
# Follow redirect to login page
redirect_url = page.parser.at('meta[http-equiv="refresh"]')['content'][/URL=(.+)/, 1]
page = agent.get(redirect_url)
# Login to DMV Site
form = page.forms[1]
form.tempOlNum = '' # DRIVER'S LICENSE NUMBER (XXXXXXXX format, ex: 12345678)
form.tempDateOfBirth = '' # DATE OF BIRTH (mm/dd/yyyy format ex: 01/01/2010)
button = form.buttons.first
page = agent.submit(form, button)
# Search default county exam sites
form = page.forms[1]
# check the reschedule box if an exam is already scheduled
unless form.radiobutton_with(:value => '0#RESCHEDULE_EXAM').nil?
form.radiobutton_with(:value => '0#RESCHEDULE_EXAM').check
end
button = form.buttons.first
page = agent.submit(form, button)
# Search all exam sites
form = page.forms[1]
button = form.buttons.first
form.checkboxes.each do |checkbox|
checkbox.checked = true
end
page = agent.submit(form, button)
until false
puts "Checking..."
sleep 60
form = page.forms[1]
button = form.buttons.first
form.checkboxes.each do |checkbox|
checkbox.checked = true
end
page = agent.submit(form, button)
#puts page.content
if examAvailable? page
puts "Exam Found!"
emailbody = ""
page.forms[1].radiobuttons.each do |examtime|
emailbody += examtime.value + "\n"
end
puts emailbody
send_email "sgweb@rit.edu", :body => emailbody
form = page.forms[1]
form.radiobutton_with(:value => 'esSearchCriteria').check
button = form.button_with(:name => 'continueButton')
page = agent.submit(form, button)
end
end
end
def main
agent = Mechanize.new
login(agent)
end
def examAvailable?(page)
!page.forms[1].radiobutton_with(:name => "selDtTimeLen").nil?
end
main
@mike-u
Copy link

mike-u commented Feb 8, 2018

Hey, this seems very useful, but do you think it's defeated now by the "I'm not a robot" captcha?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment