2013-03-19 21:49:44 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'net/http'
|
|
|
|
require 'uri'
|
|
|
|
require 'twilio-ruby'
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
abort "usage: ./check.rb SEMESTER SUBJECT COURSE [SECTIONS]\n" unless ARGV.length > 2
|
|
|
|
|
|
|
|
settings = YAML.load_file('conf/settings.yml')
|
|
|
|
|
|
|
|
semesters = {
|
2013-10-09 20:26:43 -04:00
|
|
|
'US13' => 'US131132summer 2013', 'FS13' => 'FS131134fall 2013',
|
2014-03-17 10:50:37 -04:00
|
|
|
'SS14' => 'SS141136spring 2014',
|
|
|
|
'US14' => 'US141142summer 2014',
|
2013-03-19 21:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
semester = ARGV.shift
|
|
|
|
subject = ARGV.shift
|
|
|
|
course = ARGV.shift
|
|
|
|
sections = ARGV
|
|
|
|
|
|
|
|
abort "Requires a valid semester code\n" unless semesters.has_key?(semester)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
'Semester' => semesters[semester],
|
2013-10-09 20:26:43 -04:00
|
|
|
'Post' => 'Y', 'Button' => '', 'Online' => '',
|
|
|
|
'Subject' => subject, 'CourseNumber'=> course,
|
2013-03-19 21:49:44 -04:00
|
|
|
'Instructor' => 'ANY',
|
2013-10-09 20:26:43 -04:00
|
|
|
'StartTime' => '0600', 'EndTime' => '2350',
|
|
|
|
'OnBeforeDate' => '', 'OnAfterDate' => '',
|
|
|
|
'Sunday' => 'Su', 'Monday' => 'M', 'Tuesday' => 'Tu',
|
|
|
|
'Wednesday' => 'W', 'Thursday' => 'Th', 'Friday' => 'F',
|
2013-03-19 21:49:44 -04:00
|
|
|
'Saturday' => 'Sa',
|
2013-10-09 20:26:43 -04:00
|
|
|
'OnCampus' => 'Y', 'OffCampus' => 'Y', 'OnlineCourses' => 'Y',
|
|
|
|
'StudyAbroad' => 'Y', 'MSUDubai' => 'Y',
|
2013-03-19 21:49:44 -04:00
|
|
|
'OpenCourses' => 'A',
|
|
|
|
'Submit' => 'Search for Courses'
|
|
|
|
}
|
|
|
|
|
|
|
|
response = Net::HTTP.post_form(
|
|
|
|
URI.parse('http://schedule.msu.edu/searchResults.asp'),
|
|
|
|
data
|
|
|
|
)
|
|
|
|
|
|
|
|
courses = response.body.scan(/<a.*?title="(.*?) Section - LOG IN to add Section (.*?) to your planner">.*<\/a>/)
|
|
|
|
|
|
|
|
open = Array.new
|
|
|
|
courses.each do |course|
|
|
|
|
open << course.last if course.first == 'Open' && sections.include?(course.last)
|
|
|
|
end
|
|
|
|
|
|
|
|
if open.length > 0
|
2014-03-17 10:50:37 -04:00
|
|
|
@client = Twilio::REST::Client.new settings['twilio']['sid'],
|
2013-03-19 21:49:44 -04:00
|
|
|
settings['twilio']['token']
|
|
|
|
|
|
|
|
@call = @client.account.calls.create(
|
|
|
|
:from => '+' + settings['application']['from'],
|
|
|
|
:to => '+' + settings['application']['to'],
|
|
|
|
:url => 'http://twimlbin.com/external/23144346c2f2a287'
|
|
|
|
)
|
|
|
|
end
|