Scripting SDSU Class Registraion

Alex Egg,


This is little script I wrote to help me register for my classes at school. The problem is that they are all full by the time my reg. time comes up. Now I have to play this game were I’m franticly checking back every 5 min to see if somebody dropped it and there’s a seat available. I then had the epiphany that this would be a lot easier if I could automate this. Thus this script was borne.

The script

It uses mechanize to log into my schools web portal and and runs an xpath the page:

My Unicorn


agent =
page = agent.get('')
page = => 'WebPortal').click
form = page.forms.first
page = agent.submit(form)
page = => 'My Registration').click
page = => 'Fall 2012').click
page = => 'My Wish List').click

[2,3,4].each do |i|"//tr/td/form/table/tr[#{i}]/td[2]/a").inner_text"//tr/td/form/table/tr[#{i}]/td[10]").inner_text, seats)
  courses.push c

courses.each do |course|
  if course.has_seats?
    m="#{} - #{} has #{course.seats} seats"
    log m
    Twitter.direct_message_create('eggie5', m)
    Twitter.direct_message_create('withlovecassee', m)
    log "no seats..."

If there is a seat available, it will send me and GF a twitter DM, which also emails me. It will also go ahead and register it for me. The reg. form looks like this:

reg form

That 4 digit number is plane-text so it’s trivial to submit the form and add the class automatically.

Setting up cron job

More harder than developing the script was setting up the cron job. I added this to my ec2 instance I have running:

*/5 * * * * /usr/local/bin/ruby /home/ubuntu/seatcheck/seatcheck.rb

which says run the seat check every 5 minutes. However, when cron runs it’s in a different env so the path is all diff and doesn’t have ruby. It took me a while to debug that. But this was a handy way to do it:

  1. Add * * * * * env > /tmp/env.output to your cron
  2. check /tmp/env.output to see what it prints compare to your env command

I wound up putting the full path to ruby to get around the path issue.

Permalink: scripting-sdsu-class-registration

Tags: programming, mechanize

Last edited by Alex Egg, 2012-08-01 19:20:23
View Revision History