osu-cc-scraper 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/osu-cc-scraper/course.rb +13 -26
- data/lib/osu-cc-scraper/department.rb +3 -4
- data/lib/osu-cc-scraper/section.rb +7 -2
- data/lib/osu-cc-scraper/university.rb +25 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49aea5047e818d92404a7f5b6d3dcbf1a987f65b
|
4
|
+
data.tar.gz: bec95b9ba989b16c91e4f12b614728bec9df8e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a49fdac45ab85eff7f81ae245d17d22832246eb7f804e32640d1311109fe3d8b6b1cb48ac1bc100da56bbb8cae6117669ff03fbdc88aba460cf23e62efbc0da
|
7
|
+
data.tar.gz: dfe8e6bbb90fae2d24c0a14dbb4cb33f0f5a8695b97b7233752756a16d5ac83a0880a6f081ffb9b3db51790c3ceea0809e5c9c517644a09f688e2d005d3bc779
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require "open-uri"
|
2
2
|
require "oga"
|
3
|
-
|
4
3
|
require "osu-cc-scraper/section"
|
5
4
|
|
6
5
|
module OsuCcScraper
|
7
|
-
class Course < Struct.new(:
|
6
|
+
class Course < Struct.new(:department, :course_number, :name)
|
8
7
|
|
9
8
|
def sections
|
10
9
|
html = fetch_sections
|
@@ -17,23 +16,22 @@ module OsuCcScraper
|
|
17
16
|
TITLE_XPATH = "//form/h3"
|
18
17
|
|
19
18
|
def fetch_sections
|
20
|
-
open("#{ENDPOINT}/CourseDetail.aspx?subjectcode=#{subject_code}&coursenumber=#{course_number}").read
|
19
|
+
open("#{ENDPOINT}/CourseDetail.aspx?subjectcode=#{department.subject_code}&coursenumber=#{course_number}").read
|
21
20
|
end
|
22
21
|
|
23
22
|
def parse_sections(html)
|
24
23
|
document = Oga.parse_html(html)
|
25
24
|
|
26
|
-
document.xpath(SECTIONS_XPATH).map { |row|
|
25
|
+
document.xpath(SECTIONS_XPATH).map { |row|
|
27
26
|
Section.new(
|
28
|
-
|
29
|
-
|
30
|
-
parse_name(document),
|
31
|
-
parse_term(row),
|
27
|
+
self,
|
28
|
+
parse_term(row),
|
32
29
|
parse_section(row),
|
33
|
-
parse_instructor(row),
|
34
|
-
|
30
|
+
parse_instructor(row),
|
31
|
+
parse_campus(row),
|
32
|
+
parse_type(row),
|
35
33
|
parse_status(row),
|
36
|
-
parse_capacity(row),
|
34
|
+
parse_capacity(row),
|
37
35
|
parse_current(row)
|
38
36
|
)
|
39
37
|
}
|
@@ -43,21 +41,6 @@ module OsuCcScraper
|
|
43
41
|
document.xpath(selector)&.text&.delete("\r\n")&.strip
|
44
42
|
end
|
45
43
|
|
46
|
-
def parse_department(document)
|
47
|
-
title = document.xpath(TITLE_XPATH).text.split("\n")
|
48
|
-
title[2].delete("\r\n").strip[0..-2].split(" ")[0]
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_number(document)
|
52
|
-
title = document.xpath(TITLE_XPATH).text.split("\n")
|
53
|
-
title[2].split(" ")[1][0..-2]
|
54
|
-
end
|
55
|
-
|
56
|
-
def parse_name(document)
|
57
|
-
title = document.xpath(TITLE_XPATH).text.split("\n")
|
58
|
-
title[3].strip
|
59
|
-
end
|
60
|
-
|
61
44
|
def parse_term(row)
|
62
45
|
fetch_column(row, "td[position() = 1]")
|
63
46
|
end
|
@@ -70,6 +53,10 @@ module OsuCcScraper
|
|
70
53
|
fetch_column(row, "td[position() = 6]")
|
71
54
|
end
|
72
55
|
|
56
|
+
def parse_campus(row)
|
57
|
+
fetch_column(row, "td[position() = 9]")
|
58
|
+
end
|
59
|
+
|
73
60
|
def parse_type(row)
|
74
61
|
fetch_column(row, "td[position() = 11]")
|
75
62
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require "open-uri"
|
2
2
|
require "oga"
|
3
|
-
|
4
3
|
require "osu-cc-scraper/course"
|
5
4
|
|
6
5
|
module OsuCcScraper
|
7
|
-
class Department < Struct.new(:name, :subject_code)
|
6
|
+
class Department < Struct.new(:university, :name, :subject_code)
|
8
7
|
|
9
8
|
def courses
|
10
9
|
html = fetch_courses
|
@@ -14,14 +13,14 @@ module OsuCcScraper
|
|
14
13
|
private
|
15
14
|
|
16
15
|
def fetch_courses
|
17
|
-
open("#{ENDPOINT}/CourseList.aspx?subjectcode=#{subject_code}&level
|
16
|
+
open("#{ENDPOINT}/CourseList.aspx?subjectcode=#{subject_code}&level=#{university.level}").read
|
18
17
|
end
|
19
18
|
|
20
19
|
def parse_courses(html)
|
21
20
|
document = Oga.parse_html(html)
|
22
21
|
document.xpath("//tr//td//strong/a[last()]").map { |row|
|
23
22
|
Course.new(
|
24
|
-
|
23
|
+
self,
|
25
24
|
parse_course_course_number(row),
|
26
25
|
parse_course_name(row)
|
27
26
|
)
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module OsuCcScraper
|
2
|
-
class Section < Struct.new(:
|
3
|
-
:
|
2
|
+
class Section < Struct.new(:course, :term, :section, :instructor, :campus,
|
3
|
+
:type, :status, :capacity, :current)
|
4
|
+
def to_a
|
5
|
+
[ course.department.subject_code, course.course_number, course.name,
|
6
|
+
term, section, instructor, campus, type, status, capacity, current ]
|
7
|
+
end
|
8
|
+
|
4
9
|
end
|
5
10
|
end
|
@@ -1,37 +1,39 @@
|
|
1
1
|
require "open-uri"
|
2
2
|
require "oga"
|
3
|
-
|
4
3
|
require "osu-cc-scraper/department"
|
5
4
|
|
6
5
|
module OsuCcScraper
|
7
|
-
class University
|
6
|
+
class University < Struct.new(:level)
|
8
7
|
|
9
8
|
def departments
|
10
9
|
html = fetch_departments
|
11
10
|
parse_departments(html)
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
13
|
+
private
|
14
|
+
|
15
|
+
def fetch_departments
|
16
|
+
open("#{ENDPOINT}/CourseDescription.aspx?level=#{level}").read
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_departments(html)
|
20
|
+
ng = Oga.parse_html(html)
|
21
|
+
ng.xpath("//tr/td/font/a").map { |row|
|
22
|
+
Department.new(
|
23
|
+
self,
|
24
|
+
parse_department_name(row),
|
25
|
+
parse_department_subject_code(row),
|
26
|
+
)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_department_subject_code(row)
|
31
|
+
row.text[/\(.*?\)/][1..-2]
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_department_name(row)
|
35
|
+
row.text[/([^(]+)/].strip
|
36
|
+
end
|
35
37
|
|
36
38
|
end
|
37
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osu-cc-scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonah George
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oga
|