Skip to content

Instantly share code, notes, and snippets.

@jhsu
Created August 30, 2011 23:29
Show Gist options
  • Save jhsu/1182389 to your computer and use it in GitHub Desktop.
Save jhsu/1182389 to your computer and use it in GitHub Desktop.
UB Open courses checker (HUB Student Center)
rvm use 1.8.7

UB course opening checker

Screenshot

checks if the courses in your UB HUB Student Center are open / closed

Install

git clone git://gist.github.com/1182389.git ub_courses
cd ub_courses
# make sure you have ruby 1.8.7 installed (required by mechanize)
bundle install
ruby check.rb
# enter your username and password
require 'bundler'
Bundler.require
high = HighLine.new
username = high.ask("Enter your username: ")
password = high.ask("Enter your password: ") { |q| q.echo = false }
while true
agent = Mechanize.new
page = agent.get('https://ubsis.buffalo.edu/psc/csprdss/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES_2.SSR_SSENRL_CART.GBL?Page=SSR_SSENRL_CART&Action=A')
# Login Page
login_form = page.form('f')
login_form.j_username = username
login_form.j_password = password
page = agent.submit(login_form, login_form.buttons.first)
form = page.forms.first
page = agent.submit(form, form.buttons.first)
# Cart
page.search('table.PSLEVEL1GRIDNBO tr').each do |ele|
columns = ele.search('td')
if columns[1]
course = columns[1].search('span').inner_text.gsub("\r",'')
status = columns[-1].search('img').attr('alt')
high.say("#{ high.color(status, (status.to_s == 'Open' ? :green : :red )) } - #{course}\n")
end
end
puts "===========#{Time.now}============"
sleep(60)
end
source :rubygems
gem 'highline'
gem 'mechanize'
GEM
remote: http://rubygems.org/
specs:
highline (1.6.2)
mechanize (2.0.1)
net-http-digest_auth (>= 1.1.1, ~> 1.1)
net-http-persistent (~> 1.8)
nokogiri (~> 1.4)
webrobots (>= 0.0.9, ~> 0.0)
net-http-digest_auth (1.1.1)
net-http-persistent (1.9)
nokogiri (1.5.0)
webrobots (0.0.11)
nokogiri (>= 1.4.4)
PLATFORMS
ruby
DEPENDENCIES
highline
mechanize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment