Created
June 17, 2014 14:30
-
-
Save eric-wood/b18787bfc41354f09e85 to your computer and use it in GitHub Desktop.
Scan TAMU course catalog for open seats and notify user when one opens up
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 'uri' | |
require 'open-uri' | |
BASE_URI = "https://compass-ssb.tamu.edu/pls/PROD/bwykschd.p_disp_detail_sched?term_in=201431&crn_in=" | |
# each course is represented by a CRN number | |
crns = %w[21179 12263 12265 12266 12267 12268 12271 21180] | |
def notify(url) | |
puts "HOLY SHIT! #{url}" | |
end | |
loop do | |
crns.each do |crn| | |
uri = URI(BASE_URI + crn) | |
# request the course data | |
response = uri.read | |
# their markup sucks horrifically...it's actually easier to use a regex :( | |
matches = response.scan(/<TD CLASS="dddefault">([0-9]+)<\/TD>/) | |
capacity = matches[0].first.to_i | |
actual = matches[1].first.to_i | |
open_seats = capacity - actual | |
puts "#{crn} -- #{open_seats}" | |
notify(uri.to_s) if open_seats > 0 | |
# wait a sec before procressing more... | |
sleep 5 | |
end | |
# Howdy is dumb as shit but let's try not to flood them anyways... | |
sleep 60 | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment