Created
January 21, 2012 05:19
-
-
Save hoisie/1651479 to your computer and use it in GitHub Desktop.
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 'rubygems' | |
require 'mechanize' | |
keywords = ['marie', 'dusch', 'spinning', '6:15'] | |
#keywords = ['bodypump', '5:10', 'kimi', 'hori'] | |
users = [['user1', 'password1'], ['user2', 'password2']] | |
puts "Registering for class #{keywords.inspect}" | |
users.each do |user| | |
email, password = user | |
puts email, password | |
#choose club 'ucsf' | |
agent = Mechanize.new | |
agent.user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:5.0) Gecko/20100101 Firefox/5.0" | |
page = agent.get('http://www.xpiron.com/schedule') | |
lookup_form = page.form('chooseForm') | |
lookup_form.pUrl = 'ucsf' | |
page = agent.submit(lookup_form) | |
#login | |
login_form = page.form('login') | |
login_form.pEmailAddr = email | |
login_form.pPassword = password | |
page = agent.submit(login_form) | |
#click PARNASSUS GROUP FITNESS link | |
page = page.link_with(:text => 'PARNASSUS GROUP FITNESS').click | |
#click the signup link | |
page = page.links.select {|link| link.href =~ /^Booking.*/}.first.click | |
#find the right class | |
matches = page.search('//a[starts-with(@href, "Group")]').select do |link| | |
text = link.parent.parent.parent.text.downcase | |
keywords.map {|k| text.index(k)}.compact.count == keywords.count | |
end | |
if matches.count == 0 | |
puts "Could not find class with keywords #{keywords.inspect}" | |
exit(0) | |
end | |
href = matches.first["href"] | |
group_event_id = href.match(/pGroupEventID=(\d+)/)[1] | |
service_id = href.match(/pServiceID=(\d+)/)[1] | |
#Click "Make booking" | |
bookingUrl = "Group?pAction=630&pFunction=PA&pGroupEventID=#{group_event_id}&pServiceID=#{service_id}" | |
page = agent.get(bookingUrl) | |
if page.title =~ /^Booking Not Allowed/ | |
puts "Booking Not Allowed - Trying to book too early" | |
next | |
end | |
#Click "Okay" | |
signup_form = page.forms[0] | |
signup_form.pAction = "630" | |
signup_form.pFunction="C" | |
signup_form.pBookingType="CL" | |
signup_form.pRecalculate="Y" | |
page = agent.submit(signup_form) | |
puts "Success!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment