thu_student 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +35 -27
- data/README.md +14 -7
- data/lib/thu_student.rb +95 -56
- data/lib/thu_student/version.rb +3 -2
- data/thu_student.gemspec +3 -1
- metadata +35 -8
- data/pkg/thu_student-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d29d818e4fc5c7d73cd8de3d789e2cb67c8ffa8d
|
4
|
+
data.tar.gz: e7ab5c21241696fe00b5e59549b4244d186dd23c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 824580dfe432e39ee5dfcb5e2ec14909940eed7db9a9d2242aacd4f44b4c96a2130a4db25d398f5b49851eccae80311f78c9eb5db6a8ea8c5dfe2683e30305ff
|
7
|
+
data.tar.gz: 46062b9be5187c30285604b5e4214d2fd5340029b72365e2be5261c141aac5b895cce80657f7698e591adba0ecccacea4545dcc7992f661d5fc9cb7ca18e1def
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,45 +1,53 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
thu_student (0.1.
|
5
|
-
|
4
|
+
thu_student (0.1.2)
|
5
|
+
capybara
|
6
|
+
nokogiri
|
7
|
+
poltergeist
|
6
8
|
|
7
9
|
GEM
|
8
10
|
remote: https://rubygems.org/
|
9
11
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
12
|
+
addressable (2.4.0)
|
13
|
+
capybara (2.7.1)
|
14
|
+
addressable
|
15
|
+
mime-types (>= 1.16)
|
16
|
+
nokogiri (>= 1.3.3)
|
17
|
+
rack (>= 1.0.0)
|
18
|
+
rack-test (>= 0.5.4)
|
19
|
+
xpath (~> 2.0)
|
20
|
+
cliver (0.3.2)
|
21
|
+
mime-types (3.1)
|
22
|
+
mime-types-data (~> 3.2015)
|
23
|
+
mime-types-data (3.2016.0521)
|
24
|
+
mini_portile2 (2.1.0)
|
25
|
+
nokogiri (1.7.0.1)
|
26
|
+
mini_portile2 (~> 2.1.0)
|
27
|
+
poltergeist (1.13.0)
|
28
|
+
capybara (~> 2.1)
|
29
|
+
cliver (~> 0.3.1)
|
30
|
+
websocket-driver (>= 0.2.0)
|
31
|
+
rack (2.0.1)
|
32
|
+
rack-test (0.6.3)
|
33
|
+
rack (>= 1.0)
|
30
34
|
rake (10.5.0)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
websocket-driver (0.6.4)
|
36
|
+
websocket-extensions (>= 0.1.0)
|
37
|
+
websocket-extensions (0.1.2)
|
38
|
+
xpath (2.0.0)
|
39
|
+
nokogiri (~> 1.3)
|
35
40
|
|
36
41
|
PLATFORMS
|
37
42
|
ruby
|
38
43
|
|
39
44
|
DEPENDENCIES
|
40
45
|
bundler (~> 1.11)
|
46
|
+
capybara
|
47
|
+
nokogiri
|
48
|
+
poltergeist
|
41
49
|
rake (~> 10.0)
|
42
50
|
thu_student!
|
43
51
|
|
44
52
|
BUNDLED WITH
|
45
|
-
1.
|
53
|
+
1.12.5
|
data/README.md
CHANGED
@@ -4,8 +4,14 @@
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
+
需要安裝 phantomjs
|
8
|
+
```bash
|
9
|
+
$ npm install -g phantomjs
|
10
|
+
```
|
11
|
+
|
7
12
|
加入這行到您的 Gemfile:
|
8
13
|
|
14
|
+
|
9
15
|
```ruby
|
10
16
|
gem 'thu_student'
|
11
17
|
```
|
@@ -20,16 +26,17 @@ Or install it yourself as:
|
|
20
26
|
|
21
27
|
## Usage
|
22
28
|
|
23
|
-
取得個人基本資料
|
24
|
-
|
25
29
|
```ruby
|
26
|
-
|
27
|
-
```
|
30
|
+
student = ThuStudent.new('student_id','password')
|
28
31
|
|
29
|
-
|
32
|
+
student.profile
|
33
|
+
#profile 個人資料
|
30
34
|
|
31
|
-
|
32
|
-
|
35
|
+
student.course_info
|
36
|
+
#course_info 學程資訊
|
37
|
+
|
38
|
+
student.course
|
39
|
+
#course 歷年修課紀錄
|
33
40
|
```
|
34
41
|
|
35
42
|
## Development
|
data/lib/thu_student.rb
CHANGED
@@ -1,73 +1,112 @@
|
|
1
1
|
require 'thu_student/version'
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
form = page.forms.first
|
2
|
+
require 'rubygems'
|
3
|
+
require 'capybara'
|
4
|
+
require 'capybara/dsl'
|
5
|
+
require 'capybara/poltergeist'
|
6
|
+
require 'nokogiri'
|
8
7
|
|
9
|
-
form['username'] = username
|
10
|
-
form['passwd'] = password
|
11
8
|
|
12
|
-
|
13
|
-
|
9
|
+
Capybara.javascript_driver = :poltergeist
|
10
|
+
Capybara.current_driver = :poltergeist
|
11
|
+
Capybara.register_driver :poltergeist do |app|
|
12
|
+
Capybara::Poltergeist::Driver.new(app, js_errors: false)
|
13
|
+
end
|
14
|
+
|
15
|
+
class ThuStudent
|
16
|
+
include Capybara::DSL
|
14
17
|
|
15
|
-
|
18
|
+
attr_reader :profile
|
19
|
+
attr_reader :course_info
|
20
|
+
attr_reader :course
|
16
21
|
|
17
|
-
|
22
|
+
def initialize(id, password)
|
23
|
+
visit('http://fsis.thu.edu.tw/mosi/ccsd3/index.php?job=stud&loginn=&r=http://fsis.thu.edu.tw/')
|
24
|
+
find('#login-username').set(id)
|
25
|
+
find('#login-password').set(password)
|
26
|
+
find('button').click
|
27
|
+
visit('http://fsiso.thu.edu.tw/wwwstud/STUD_V6/INFO/MyProfile.php?job=personinfo')
|
28
|
+
@profile = profile_parse(html)
|
29
|
+
visit('http://fsiso.thu.edu.tw/wwwstud/STUD_V6/INFO/MyProfile.php?job=courseinfo')
|
30
|
+
@course_info = course_info_parse(html)
|
31
|
+
visit('http://fsiso.thu.edu.tw/wwwstud/STUD_V6/COURSE/rcrd_all.php')
|
32
|
+
@course = course_parse(html)
|
33
|
+
end
|
18
34
|
|
19
|
-
|
20
|
-
name = profiles[1].text.split(":").last
|
21
|
-
sex = profiles[2].text.split(":").last
|
22
|
-
birthday = profiles[3].text.split(":").last
|
23
|
-
birth_year = birthday.split(' ')[1].to_i + 1911
|
24
|
-
birth_month = birthday.split(' ')[3]
|
25
|
-
birth_day = birthday.split(' ')[5]
|
26
|
-
birthday = "#{birth_year}/#{birth_month}/#{birth_day}"
|
27
|
-
id = profiles[4].text.split(":").last
|
28
|
-
type = profiles[5].text.split(":").last
|
29
|
-
grade = profiles[6].text.split(":").last
|
30
|
-
identity = profiles[7].text.split(":").last
|
31
|
-
country = profiles[8].text.split(":").last
|
32
|
-
status = profiles[9].text.split(":").last
|
33
|
-
guardian = profiles[10].text.split(":").last
|
34
|
-
home_address = profiles[11].text.split(":").last
|
35
|
-
home_phone = profiles[12].text.split(":").last
|
36
|
-
address = profiles[13].text.split(":").last
|
37
|
-
use_phone = profiles[14].text.split(":").last
|
38
|
-
telephone = profiles[15].text.split(":").last
|
35
|
+
private
|
39
36
|
|
40
|
-
|
37
|
+
def profile_parse(html)
|
38
|
+
profile = Nokogiri::HTML(html)
|
39
|
+
profile = profile.css('table tbody tr td')
|
40
|
+
profile = profile.map { |n| clean_data(n) }
|
41
|
+
profile_data = {}
|
42
|
+
profile_data[:student_id] = profile[0]
|
43
|
+
profile_data[:name] = profile[1]
|
44
|
+
profile_data[:sex] = profile[2]
|
45
|
+
birthday = profile[3].split(' ')
|
46
|
+
profile_data[:birthday] = [birthday[1].to_i + 1911,
|
47
|
+
birthday[3],
|
48
|
+
birthday[5]].join('-')
|
49
|
+
profile_data[:id] = profile[4]
|
50
|
+
profile_data[:type] = profile[5]
|
51
|
+
grade = profile[6].split(' ')
|
52
|
+
profile_data[:department] = grade[0]
|
53
|
+
profile_data[:grade] = grade[1]
|
54
|
+
profile_data[:identity] = profile[7]
|
55
|
+
profile_data[:country] = profile[8]
|
56
|
+
profile_data[:status] = profile[9]
|
57
|
+
profile_data[:guardian] = profile[10]
|
58
|
+
profile_data[:home_address] = profile[11]
|
59
|
+
profile_data[:home_phone] = profile[12]
|
60
|
+
profile_data[:address] = profile[13]
|
61
|
+
profile_data[:use_phone] = profile[14]
|
62
|
+
profile_data[:telephone] = profile[15]
|
41
63
|
|
42
|
-
|
64
|
+
profile_data
|
43
65
|
end
|
44
66
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
67
|
+
def course_info_parse(html)
|
68
|
+
course_info = Nokogiri::HTML(html)
|
69
|
+
course_info = course_info.css('table tbody tr td')
|
70
|
+
course_info = course_info.map { |n| clean_data(n) }
|
71
|
+
course_info_data = {}
|
72
|
+
course_info_data[:minor] = course_info[0]
|
73
|
+
course_info_data[:double_major] = course_info[1]
|
74
|
+
course_info_data[:program] = course_info[2]
|
75
|
+
course_info_data[:edu_program] = course_info[3]
|
49
76
|
|
50
|
-
|
51
|
-
|
77
|
+
course_info_data
|
78
|
+
end
|
52
79
|
|
53
|
-
|
54
|
-
|
80
|
+
def course_parse(html)
|
81
|
+
course = Nokogiri::HTML(html)
|
82
|
+
course = course.css('#no-more-tables table tbody tr')
|
83
|
+
course_data = []
|
84
|
+
course.each do |c|
|
85
|
+
course_data << clean_course(c)
|
86
|
+
end
|
55
87
|
|
56
|
-
|
88
|
+
course_data
|
89
|
+
end
|
57
90
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
91
|
+
def clean_course(course_tr)
|
92
|
+
course_td = course_tr.css('td')
|
93
|
+
course_td = course_td.map(&:text)
|
94
|
+
course = {}
|
95
|
+
year = course_td[0] + course_td[1]
|
96
|
+
course[:year] = year
|
97
|
+
course[:id] = course_td[2]
|
98
|
+
course[:name] = course_td[3]
|
99
|
+
course[:credit] = course_td[4]
|
100
|
+
course[:score] = course_td[5]
|
101
|
+
|
102
|
+
course
|
103
|
+
end
|
70
104
|
|
71
|
-
|
105
|
+
def clean_data(nokogiri_obj)
|
106
|
+
str = nokogiri_obj.text.split(":")
|
107
|
+
count = str.count
|
108
|
+
str = str.last.strip
|
109
|
+
str = nil if str == "無" || str == " " || count < 2
|
110
|
+
str
|
72
111
|
end
|
73
112
|
end
|
data/lib/thu_student/version.rb
CHANGED
data/thu_student.gemspec
CHANGED
@@ -28,6 +28,8 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 1.11"
|
30
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
-
spec.add_runtime_dependency "
|
31
|
+
spec.add_runtime_dependency "nokogiri"
|
32
|
+
spec.add_runtime_dependency "capybara"
|
33
|
+
spec.add_runtime_dependency "poltergeist"
|
32
34
|
|
33
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thu_student
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- herber523
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,19 +39,47 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: nokogiri
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: poltergeist
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
82
|
+
version: '0'
|
55
83
|
description: Write a longer description or delete this line.
|
56
84
|
email:
|
57
85
|
- herber523@gmail.com
|
@@ -67,7 +95,6 @@ files:
|
|
67
95
|
- bin/setup
|
68
96
|
- lib/thu_student.rb
|
69
97
|
- lib/thu_student/version.rb
|
70
|
-
- pkg/thu_student-0.1.0.gem
|
71
98
|
- thu_student.gemspec
|
72
99
|
homepage: https://github.com/herber523/thu_course
|
73
100
|
licenses: []
|
data/pkg/thu_student-0.1.0.gem
DELETED
Binary file
|