osu-ctl-scraper 1.0.0 → 1.0.1
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 +4 -4
- data/lib/osu-ctl-scraper.rb +1 -0
- data/lib/osu-ctl-scraper/book.rb +17 -8
- data/lib/osu-ctl-scraper/department.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37bb61bf74de86fd115f1b1f882cd7ba718a1c58
|
4
|
+
data.tar.gz: ae2c386e394e04c5dcaf47b0d4305279522388fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60432b3d327c03fc4b351bb9209b101d1cca9b0e26d092cc541cfb26dcd16b6d6ff1f1530013a447287c21f5494fbcc627ccccb279028c6f0f0d922fd3b89e34
|
7
|
+
data.tar.gz: df06011ff10ca5aeecfbba2544ab3497185a06b2cc1a7ec3827eba54ccea108774dc3f447da829acc46c5111e097c3491fdd5f3bf69482959b7ad8494b0e58d2
|
data/lib/osu-ctl-scraper.rb
CHANGED
data/lib/osu-ctl-scraper/book.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
module OsuCtlScraper
|
2
2
|
class Book
|
3
|
-
|
3
|
+
RESOURCE = "/Faculty/GetTextbooks/"
|
4
|
+
|
5
|
+
# Returns an array of Books
|
4
6
|
#
|
5
|
-
# @param [
|
7
|
+
# @param [String] subject_code
|
8
|
+
# @param [Integer] year
|
9
|
+
# @param [Symbol] term Must be one of: "winter", "spring", "summer", or "fall"
|
6
10
|
# @return [Array<Hash>]
|
7
|
-
def self.
|
11
|
+
def self.find_by(subject_code, year, term)
|
8
12
|
res = get_html(subject_code, year, term)
|
9
13
|
html = format_response(res.body)
|
10
14
|
process_html(subject_code, html)
|
@@ -15,7 +19,7 @@ module OsuCtlScraper
|
|
15
19
|
# @param [Symbol] term Must be one of: "winter", "spring", "summer", or "fall"
|
16
20
|
# @return [String]
|
17
21
|
def self.get_html(subject_code, year, term)
|
18
|
-
url = URI.parse("
|
22
|
+
url = URI.parse("#{ENDPOINT}#{RESOURCE}")
|
19
23
|
params = form_params(subject_code, year, term)
|
20
24
|
res = Net::HTTP.post_form(url, params)
|
21
25
|
end
|
@@ -60,16 +64,18 @@ module OsuCtlScraper
|
|
60
64
|
ng = Nokogiri::HTML(html)
|
61
65
|
ng.css("tr:not(:first-child)").each do |row|
|
62
66
|
book = process_row(row)
|
63
|
-
book
|
64
|
-
|
67
|
+
unless book.nil?
|
68
|
+
book[:subject_code] = subject_code
|
69
|
+
books << book
|
70
|
+
end
|
65
71
|
end
|
66
72
|
books
|
67
73
|
end
|
68
74
|
|
69
75
|
# @param [Nokogiri::XML::Element] row
|
70
|
-
# @return [Hash]
|
76
|
+
# @return [Hash, nil]
|
71
77
|
def self.process_row(row)
|
72
|
-
{
|
78
|
+
book = {
|
73
79
|
course: row.css("td:nth-child(1)").text.strip,
|
74
80
|
section: row.css("td:nth-child(2)").text.strip,
|
75
81
|
instructor: row.css("td:nth-child(3)").text.strip,
|
@@ -83,6 +89,9 @@ module OsuCtlScraper
|
|
83
89
|
comments: row.css("td:nth-child(11)").text.strip,
|
84
90
|
req_date: row.css("td:nth-child(12)").text.strip
|
85
91
|
}
|
92
|
+
|
93
|
+
# Only return the book if is has an ISBN
|
94
|
+
book[:isbn].empty? ? nil : book
|
86
95
|
end
|
87
96
|
end
|
88
97
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module OsuCtlScraper
|
2
2
|
class Department
|
3
|
+
RESOURCE = "/faculty/textbooks/"
|
4
|
+
|
3
5
|
# @return [Array<Hash>]
|
4
6
|
def self.all
|
5
7
|
html = get_html
|
@@ -8,7 +10,7 @@ module OsuCtlScraper
|
|
8
10
|
|
9
11
|
# @return [String] html
|
10
12
|
def self.get_html
|
11
|
-
open("
|
13
|
+
open("#{ENDPOINT}#{RESOURCE}").read
|
12
14
|
end
|
13
15
|
|
14
16
|
# @param [String] html
|