thu_course 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/thu_course/version.rb +1 -1
- data/lib/thu_course.rb +76 -64
- 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: 544545f984455ba04e1205085ae35c250e79e740
|
4
|
+
data.tar.gz: b52295ae35d5ace8e2a1db94b4275b5bc6171ff4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0911451676a4f32cdf99c3dc7b58d25c49e0a286a9f6524568747e3f29fa6e48f4f31630c5e5fbfdf59251c7a0890c4f5e71a1ad68bf4cf5e1d07982f7308d69
|
7
|
+
data.tar.gz: 3f09481c4981845cea976ac274b5bef1672e4aa270c1493bfe8981fc241e529e6d2ce1f6813479e2e2f7ceb4b048c14f3f055cb4ff545a00b09d8767d859aab5
|
data/Gemfile.lock
CHANGED
data/lib/thu_course/version.rb
CHANGED
data/lib/thu_course.rb
CHANGED
@@ -1,74 +1,86 @@
|
|
1
|
-
require
|
1
|
+
require 'thu_course/version'
|
2
2
|
|
3
3
|
require 'open-uri'
|
4
4
|
require 'nokogiri'
|
5
5
|
module ThuCourse
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
def self.all(year, semester)
|
7
|
+
uri = URI("http://course.service.thu.edu.tw/view-dept/#{year}/#{semester}/everything").normalize
|
8
|
+
doc = Nokogiri::HTML(open(uri))
|
9
|
+
hash = []
|
10
|
+
a_tags = doc.css('.b a') # => array of node
|
11
|
+
a_tags.each do |a_tag|
|
12
|
+
name = a_tag.text.gsub(/\s+/, ' ').strip
|
13
|
+
dp_uri = uri.merge(a_tag['href'].gsub('view-dept', 'view-ge'))
|
14
|
+
dp_doc = Nokogiri::HTML(open(dp_uri))
|
15
|
+
tr_tag = dp_doc.css('#no-more-tables tr')
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
dp = note.split('/')[0].gsub(/\s+/,' ')
|
17
|
+
tr_tag.each do |tr|
|
18
|
+
td_tag = tr.css('td')
|
19
|
+
next unless td_tag[0]
|
20
|
+
course_id = td_tag[0].css('a').text.strip
|
21
|
+
name = td_tag[1].text.strip
|
22
|
+
credit = td_tag[2].text.strip
|
23
|
+
date = td_tag[3].text.strip
|
24
|
+
teacher = td_tag[4].text.strip
|
25
|
+
num = td_tag[5].text.strip.gsub(/\s+/, '')
|
26
|
+
note = td_tag[6].text.strip
|
28
27
|
|
29
|
-
|
28
|
+
hash << { id: course_id,
|
29
|
+
name: name,
|
30
|
+
credit: credit,
|
31
|
+
date: date,
|
32
|
+
teacher: teacher,
|
33
|
+
num: num,
|
34
|
+
note: note }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
hash
|
38
|
+
end
|
30
39
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
a_tags.each do |a_tag|
|
45
|
-
name = a_tag.text.strip
|
46
|
-
id = a_tag['href'].split('/').last
|
47
|
-
hash << {id: id, name: name}
|
48
|
-
end
|
49
|
-
return hash
|
50
|
-
end
|
51
|
-
def self.department(year,semester,id)
|
52
|
-
uri = "http://course.thu.edu.tw/view-ge/#{year}/#{semester}/#{id}"
|
53
|
-
dp_doc = Nokogiri::HTML(open(uri))
|
54
|
-
tr_tag = dp_doc.css('#no-more-tables tr')
|
55
|
-
hash = []
|
56
|
-
tr_tag.each do |tr|
|
57
|
-
td_tag = tr.css('td')
|
58
|
-
if(td_tag[0])
|
59
|
-
course_id = td_tag[0].css('a').text.strip
|
60
|
-
name = td_tag[1].text.strip
|
61
|
-
credit = td_tag[2].text.strip
|
62
|
-
date = td_tag[3].text.strip
|
63
|
-
teacher = td_tag[4].text.strip
|
64
|
-
num = td_tag[5].text.strip.gsub(/\s+/,'')
|
65
|
-
note = td_tag[6].text.strip
|
66
|
-
dp = note.split('/')[0].gsub(/\s+/,' ')
|
40
|
+
def self.department_id(year, semester)
|
41
|
+
uri = URI("http://course.service.thu.edu.tw/view-dept/#{year}/#{semester}/everything").normalize
|
42
|
+
doc = Nokogiri::HTML(open(uri))
|
43
|
+
a_tags = doc.css('.b a') # => array of node
|
44
|
+
hash = []
|
45
|
+
a_tags.each do |a_tag|
|
46
|
+
name = a_tag.text.strip
|
47
|
+
id = a_tag['href'].split('/').last
|
48
|
+
hash << { id: id,
|
49
|
+
name: name }
|
50
|
+
end
|
51
|
+
hash
|
52
|
+
end
|
67
53
|
|
68
|
-
|
54
|
+
def self.department(year, semester, id)
|
55
|
+
uri = "http://course.thu.edu.tw/view-ge/#{year}/#{semester}/#{id}"
|
56
|
+
dp_doc = Nokogiri::HTML(open(uri))
|
57
|
+
tr_tag = dp_doc.css('#no-more-tables tr')
|
58
|
+
hash = []
|
59
|
+
tr_tag.each do |tr|
|
60
|
+
td_tag = tr.css('td')
|
61
|
+
next unless td_tag[0]
|
62
|
+
course_id = td_tag[0].css('a').text.strip
|
63
|
+
name = td_tag[1].text.strip
|
64
|
+
credit = td_tag[2].text.strip
|
65
|
+
date = td_tag[3].text.strip
|
66
|
+
teacher = []
|
67
|
+
teacher_data = td_tag[4].css('a')
|
68
|
+
teacher_data.each do |td|
|
69
|
+
teacher_id = td['href'].split('/').last
|
70
|
+
teacher_name = td.text.strip
|
71
|
+
teacher << {teacher_id: teacher_id,teacher_name: teacher_name}
|
72
|
+
end
|
73
|
+
num = td_tag[5].text.strip.gsub(/\s+/, '')
|
74
|
+
note = td_tag[6].text.strip
|
69
75
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
76
|
+
hash << { id: course_id,
|
77
|
+
name: name,
|
78
|
+
credit: credit,
|
79
|
+
date: date,
|
80
|
+
teacher: teacher,
|
81
|
+
num: num,
|
82
|
+
note: note }
|
83
|
+
end
|
84
|
+
hash
|
85
|
+
end
|
74
86
|
end
|