Skip to content

Instantly share code, notes, and snippets.

@benmanns
Created November 17, 2010 22:33
Show Gist options
  • Save benmanns/704260 to your computer and use it in GitHub Desktop.
Save benmanns/704260 to your computer and use it in GitHub Desktop.
This is a library for polling Liberty's ASIST portal (hence the name).

Asistant

To get this set up you have to run custom versions of the mechanize and twiliolib gems. Unfortunately, some SSL errors and issues with Liberty's login redirect sequence forced me to hack the libraries. Hopefully I can get something "official" looking to get it pulled into the main repository, but for now, install it from my repositories.

Generic Ruby Setup

sudo apt-get install ruby

Generic RubyGems Setup

# (do not use apt-get)
mkdir ~/sources; cd ~/sources
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar -xzvf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb

Mechanize Setup

mkdir ~/sources; cd ~/sources
git clone git://github.com/benmanns/mechanize.git
cd mechanize
gem build mechanize.gemspec
gem install mechanize

Twilio Setup

mkdir ~/sources; cd ~/sources
git clone git://github.com/benmanns/twilio-ruby.git
cd twilio-ruby
rake gem
cd pkg
gem install twiliolib

Now, just run ruby asistant.rb

require 'rubygems'
require 'yaml'
begin
require 'mechanize'
rescue LoadError
puts 'This library requires the mechanize gem. You must install it from git://github.com/benmanns/mechanize.git'
end
begin
require 'twiliolib'
rescue LoadError
puts 'This library requires the twiliolib gem. You must install it from git://github.com/benmanns/twilio-ruby.git'
end
config = YAML.load_file('./config.yml')
previous_remaining = -1
count = 0
loop do
begin
agent = Mechanize.new
agent.follow_meta_refresh = true
page = agent.get 'https://www.liberty.edu/index.cfm?PID=13627'
login_form = page.form_with :name => 'loginform'
login_form.username = config['asist']['username']
login_form.password = config['asist']['password']
page = login_form.submit
page = page.link_with(:text => 'Student').click
page = page.link_with(:text => 'Registration').click
page = page.link_with(:text => 'Look Up Classes').click
term_form = page.forms.select { |f| f.field_with(:name => 'p_term') }.first
p_term = term_form.field_with(:name => 'p_term')
p_term.value = p_term.options.select { |o| o.text =~ /\ASpring 2011/ }.first.value
page = term_form.submit
# After this you can go through and search for the class. I opted to enter the URL manually because it made things simpler and less error-prone.
# Women's Literature:
# page = agent.get 'https://selfservice.liberty.edu/livedata/bwckschd.p_disp_detail_sched?term_in=201120&crn_in=20795', [], 'https://selfservice.liberty.edu/livedata/bwckschd.p_disp_listcrse?term_in=201120&subj_in=ENGL&crse_in=438&crn_in=20795'
# Philosophy (intensive):
page = agent.get 'https://selfservice.liberty.edu/livedata/bwckschd.p_disp_detail_sched?term_in=201120&crn_in=30160', [], 'https://selfservice.liberty.edu/livedata/bwckschd.p_disp_listcrse?term_in=201120&subj_in=PHIL&crse_in=201&crn_in=30160'
table = page.search('table.datadisplaytable').select { |t| t.attributes['summary'].value == 'This layout table is used to present the seating numbers.' }.first
remaining = table.children.search('td.dddefault').last.children.first.text.to_i
if previous_remaining != remaining
account = Twilio::RestAccount.new(config['twilio']['sid'], config['twilio']['token'])
data = {
'From' => config['twilio']['from'],
'To' => config['twilio']['to'],
'Body' => "There are #{remaining} spots remaining in your class.",
}
response = account.request("/#{config['twilio']['version']}/Accounts/#{config['twilio']['sid']}/SMS/Messages", 'POST', data, {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})
previous_remaining = remaining
end
count += 1
puts "Ran #{count} times - #{remaining} spots remaining."
sleep 1
rescue Exception
redo # On exceptions (page not found, internet down, etc) just restart process.
end
end
asist:
username: my_liberty_username
password: my_liberty_password
twilio:
sid: my_twilio_sid
token: my_twilio_token
version: 2010-04-01
from: my_sms_from_number
to: my_sms_to_number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment