Last active
November 22, 2016 21:44
-
-
Save diogomonica/10938825 to your computer and use it in GitHub Desktop.
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 'mechanize' | |
require 'pry' | |
def start_url() | |
return "https://booknow.appointment-plus.com/6gj719v2/" | |
end | |
url = start_url() | |
agent = Mechanize.new { |agent| | |
agent.user_agent_alias = 'Mac Safari' | |
} | |
while true | |
# Get the start page | |
start_page = agent.get(url) | |
# Bail if there are no reservations | |
exit if start_page.forms.count != 1 | |
start_form = start_page.forms.first | |
start_form.fields.last.value = 833 | |
table_page = start_form.submit | |
available_times = [] | |
table_page.links.each do |link| | |
first_match = link.href.match("201404") | |
second_match = link.href.match("201405") | |
available_times << link.href if first_match | |
available_times << link.href if second_match | |
end | |
unless available_times.empty? | |
puts "found times, emailing with: #{available_times}" | |
`echo 'Reservations just changed: "#{available_times}"' | mail -s Reservations [email protected]` | |
end | |
sleep 60 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment