mcgill-utils 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +63 -0
- data/lib/mcgill-utils.rb +3 -0
- data/lib/mcgill/vsb.rb +134 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72cd10f584b18762fbb9c4c01e117e5e196e8d88
|
4
|
+
data.tar.gz: f770ae27a72525e4072659c2b17708ad7e283d42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2bce9b8ee0f882cb4002e102b2bacc69f12fe7cb90b897a2969d2aa5578e4d46c98c49a0e8a0177f334922805387533f346adf6c3ccd5ac6c5c91e1c4a54747f
|
7
|
+
data.tar.gz: 75eb3dc7570f61a1f61cc415606f3eae6eac3231aa7f06f583909e3c2f4d5b1e805df8dcfdd6ca49266da7b8d064b52a3c03ba943fa4fbefc923a9e0c7aaf039
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Noah Lackstein
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# McGill Utilities
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Crawl McGill's website and the Visual Schedule Builder to determine which courses are being offered and information (professor, timing, capacity) for each section/
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
$ sudo gem install mcgill-utils
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
So far, the gem only encapsulates the Visual Schedule Builder API in order to provide a list of sections available for each course, along with the professor and timing, etc, of each section.
|
14
|
+
|
15
|
+
You need to provide the semester and a list of courses you're interested in. The semester is formated YYYYMM, where the month is either 05 for Summer, 09 for Fall, or 01 for Winter. Courses are formatted `CODE-###`, e.g., `MGCR-293`. Multiple courses can be given at once, either as multiple parameters or as an array.
|
16
|
+
|
17
|
+
> courses = McGill::VSB.new 201409, 'MGCR-293', 'FINE-441', 'COMP-202'
|
18
|
+
|
19
|
+
or
|
20
|
+
|
21
|
+
> courses = McGill::VSB.new 201409, ['MGCR-293', 'FINE-449', 'COMP-202']
|
22
|
+
|
23
|
+
To get information about each courses section, call `#sections`
|
24
|
+
|
25
|
+
> courses.sections
|
26
|
+
=> {"FINE-449"=>
|
27
|
+
[{:crn=>"8270",
|
28
|
+
:kind=>"Lec",
|
29
|
+
:waitlist=>false,
|
30
|
+
:teacher=>"di Pietro, Vadim",
|
31
|
+
:times=>["Thursday 6:05 PM - 8:55 PM, Sep 2 to Dec 3"],
|
32
|
+
:notes=>"Enrolment limited by program \nJoint BCom/MBA course."}],
|
33
|
+
#...
|
34
|
+
}
|
35
|
+
|
36
|
+
To check whether it's possible to register for any of the sections, call `#availability`. You'll get back a hash with the crn of the section as the key. If the section has a waitlist, then a result of `true` means that there is space for you to join the waitlist. If there's no waitlist, then `true` means you can join the section immediately. A result of `false` always means that the section, and waitlist if applicable, are full.
|
37
|
+
|
38
|
+
> courses.availability
|
39
|
+
=> {"BUSA-465"=>{10097=>true}, "COMP-202"=>{823=>true, 824=>false, 825=>false}}
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
This software is licensed under the MIT license.
|
44
|
+
|
45
|
+
Copyright (c) 2014 Noah Lackstein
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
48
|
+
of this software and associated documentation files (the "Software"), to deal
|
49
|
+
in the Software without restriction, including without limitation the rights
|
50
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
51
|
+
copies of the Software, and to permit persons to whom the Software is
|
52
|
+
furnished to do so, subject to the following conditions:
|
53
|
+
|
54
|
+
The above copyright notice and this permission notice shall be included in
|
55
|
+
all copies or substantial portions of the Software.
|
56
|
+
|
57
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
58
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
59
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
60
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
61
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
62
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
63
|
+
THE SOFTWARE.
|
data/lib/mcgill-utils.rb
ADDED
data/lib/mcgill/vsb.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
module McGill
|
2
|
+
class VSB
|
3
|
+
DAYS = {
|
4
|
+
'1' => 'Sunday',
|
5
|
+
'2' => 'Monday',
|
6
|
+
'3' => 'Tuesday',
|
7
|
+
'4' => 'Wednesday',
|
8
|
+
'5' => 'Thursday',
|
9
|
+
'6' => 'Friday',
|
10
|
+
'7' => 'Saturday'
|
11
|
+
}
|
12
|
+
|
13
|
+
# Session is the date formated as YYYYMM that the semester starts, eg 201309
|
14
|
+
# Courses is an array of courses formated like, eg, ['MCGR-293', 'COMP-202']
|
15
|
+
def initialize(session, *courses)
|
16
|
+
@session, @courses = session, courses
|
17
|
+
|
18
|
+
# We expect a 1-dimensional array of courses, but for convenience we also
|
19
|
+
# accept a list of courses as strings with the splat. In this case, we
|
20
|
+
# need to flatten the array
|
21
|
+
@courses = @courses.flatten
|
22
|
+
|
23
|
+
# Not much we can do if we aren't given any courses to look up
|
24
|
+
# Raise an exception and let the caller know they're doing it wrong
|
25
|
+
raise ArgumentError, "At least one course must be given" if @courses.empty?
|
26
|
+
|
27
|
+
# Visual Schedule Builder expects all the course codes to be uppercase
|
28
|
+
@courses.map!(&:upcase)
|
29
|
+
|
30
|
+
@results = Nokogiri::XML(open(build_url))
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns a hash, the keys are the course codes, the values an array of sections
|
34
|
+
# {"FINE-449"=>
|
35
|
+
# [{:crn=>"8270",
|
36
|
+
# :kind=>"Lec",
|
37
|
+
# :waitlist=>false,
|
38
|
+
# :teacher=>"di Pietro, Vadim",
|
39
|
+
# :times=>["Thursday 6:05 PM - 8:55 PM, Sep 2 to Dec 3"],
|
40
|
+
# :notes=>"Enrolment limited by program \nJoint BCom/MBA course."}]
|
41
|
+
# }
|
42
|
+
def sections
|
43
|
+
@courses.inject({}) do |course_list, course|
|
44
|
+
section_list = @results.xpath("//selection[contains(@key, '#{course}')]").inject([]) do |list, section|
|
45
|
+
section.xpath('block').each do |block|
|
46
|
+
# If there are no scheduled courses, give a blank array
|
47
|
+
timeblocks = block['timeblockids'].split(',') rescue []
|
48
|
+
times_list = timeblocks.inject([]) do |times, timeblock_id|
|
49
|
+
timeblock = @results.at_xpath("//timeblock[@id=#{timeblock_id}]")
|
50
|
+
|
51
|
+
start_time = format_time(timeblock['t1'])
|
52
|
+
end_time = format_time(timeblock['t2'])
|
53
|
+
|
54
|
+
times.push "#{DAYS[timeblock['day']]} #{start_time} - #{end_time}, #{timeblock['s']}"
|
55
|
+
times
|
56
|
+
end
|
57
|
+
|
58
|
+
section_info = {
|
59
|
+
crn: block['key'],
|
60
|
+
kind: block['type'],
|
61
|
+
waitlist: block['wc'].to_i > 0,
|
62
|
+
teacher: block['teacher'].empty? ? "TBA" : block['teacher'],
|
63
|
+
times: times_list.empty? ? [] : times_list,
|
64
|
+
notes: block['n'].empty? ? "" : block['n'].gsub("<br/>","\n").strip
|
65
|
+
}
|
66
|
+
|
67
|
+
list.push section_info
|
68
|
+
end
|
69
|
+
list
|
70
|
+
end
|
71
|
+
course_list[course] = section_list.uniq
|
72
|
+
course_list
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Checks whether there are seats available, or if not then whether there are open spots on the waitlist
|
77
|
+
# Returns a Hash of Courses, each Course is a Hash of CRNs with values true (open) or false (closed)
|
78
|
+
# {"BUSA-465"=>{10097=>false}, "COMP-202"=>{823=>false, 824=>false, 825=>false}}
|
79
|
+
def availability
|
80
|
+
@courses.inject({}) do |course_list, course|
|
81
|
+
section_list = @results.xpath("//selection[contains(@key, '#{course}')]").inject({}) do |list, section|
|
82
|
+
section.xpath('block').each do |block|
|
83
|
+
# seats is either 1 (available) or 0 (full), to_bool checks if it's 1
|
84
|
+
# If there are available seats, and wc is 0, then there's no waitlist and you can register
|
85
|
+
if section['seats'].to_i == 1 && block['wc'].to_i == 0
|
86
|
+
section_open = true
|
87
|
+
# If wc > 0 and ws > 0, there's a waitlist, and there's space available on it, so you can register
|
88
|
+
elsif block['wc'].to_i > 0 && block['ws'].to_i > 0
|
89
|
+
section_open = true
|
90
|
+
else
|
91
|
+
section_open = false
|
92
|
+
end
|
93
|
+
|
94
|
+
list[block['key']] = section_open
|
95
|
+
end
|
96
|
+
list
|
97
|
+
end
|
98
|
+
course_list[course] = section_list
|
99
|
+
course_list
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
# Builds the URL used by Visual Schedule Builder to get class information
|
105
|
+
# The URL for COMP-202 in 201309 would be
|
106
|
+
# https://vsb.mcgill.ca/resultset.jsp?session_201309=1&course_0_0=COMP-202&sa_0_0=tm&dropdown_0_0=al&td_0_0_0=201309
|
107
|
+
def build_url
|
108
|
+
url = "https://vsb.mcgill.ca/resultset.jsp?session_#{@session}=1"
|
109
|
+
@courses.each_with_index do |course, index|
|
110
|
+
url << "&course_#{index}_0=#{course}&sa_#{index}_0=tm&dropdown_#{index}_0=al&td_#{index}_0_0=#{@session}"
|
111
|
+
end
|
112
|
+
|
113
|
+
url
|
114
|
+
end
|
115
|
+
|
116
|
+
# VSB encodes time as the number of minutes since midnight
|
117
|
+
# This function converts it to the more human readable hour:min am/pm
|
118
|
+
def format_time(minutes)
|
119
|
+
hour = minutes.to_i / 60
|
120
|
+
min = "%02d" % (minutes.to_i % 60)
|
121
|
+
|
122
|
+
if hour > 12
|
123
|
+
hour -= 12
|
124
|
+
ampm = 'PM'
|
125
|
+
elsif hour == 12
|
126
|
+
ampm = 'PM'
|
127
|
+
else
|
128
|
+
ampm = 'AM'
|
129
|
+
end
|
130
|
+
|
131
|
+
"#{hour}:#{min} #{ampm}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mcgill-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Noah Lackstein
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: |2
|
28
|
+
Crawl McGill's website and the Visual Schedule Builder to determine which
|
29
|
+
courses are being offered and information (professor, timing, capacity) for each section
|
30
|
+
email: noah@lackstein.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/mcgill/vsb.rb
|
36
|
+
- lib/mcgill-utils.rb
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
homepage: http://github.com/lackstein/mcgill
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.1.11
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Retrieve information for courses being offered by McGill
|
63
|
+
test_files: []
|