thu_student 0.1.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8205ff5a6d8b79f59e40ec3cdefabd94a7aeeec3
4
- data.tar.gz: 620c70be70f8bc30a1eee7b96fbf4e8473a39ab0
3
+ metadata.gz: d29d818e4fc5c7d73cd8de3d789e2cb67c8ffa8d
4
+ data.tar.gz: e7ab5c21241696fe00b5e59549b4244d186dd23c
5
5
  SHA512:
6
- metadata.gz: 13151750f77ee182b60f5875e6a16d6794268a930942a900e02d5dc4f3ec15e1204275830d2ac0a56946162cc41a8bed0ac5274029e2b15760a7b1fcf6cbb01c
7
- data.tar.gz: 44806e431fea816f029612d0b2162c2ebda8b110a999562c4afdb5a76910532b0ea055119dac1b3cd82be404863d6cd79ac42b153b3111fa09eb6a5ad19fad5d
6
+ metadata.gz: 824580dfe432e39ee5dfcb5e2ec14909940eed7db9a9d2242aacd4f44b4c96a2130a4db25d398f5b49851eccae80311f78c9eb5db6a8ea8c5dfe2683e30305ff
7
+ data.tar.gz: 46062b9be5187c30285604b5e4214d2fd5340029b72365e2be5261c141aac5b895cce80657f7698e591adba0ecccacea4545dcc7992f661d5fc9cb7ca18e1def
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
- require 'mechanize'
2
+ gem 'capybara'
3
+ gem 'nokogiri'
4
+ gem 'poltergeist'
3
5
  # Specify your gem's dependencies in thu_student.gemspec
4
6
  gemspec
@@ -1,45 +1,53 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- thu_student (0.1.0)
5
- mechanize (~> 2.7.0)
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
- domain_name (0.5.20160310)
11
- unf (>= 0.0.5, < 1.0.0)
12
- http-cookie (1.0.2)
13
- domain_name (~> 0.5)
14
- mechanize (2.7.4)
15
- domain_name (~> 0.5, >= 0.5.1)
16
- http-cookie (~> 1.0)
17
- mime-types (>= 1.17.2, < 3)
18
- net-http-digest_auth (~> 1.1, >= 1.1.1)
19
- net-http-persistent (~> 2.5, >= 2.5.2)
20
- nokogiri (~> 1.6)
21
- ntlm-http (~> 0.1, >= 0.1.1)
22
- webrobots (>= 0.0.9, < 0.2)
23
- mime-types (2.99.1)
24
- mini_portile2 (2.0.0)
25
- net-http-digest_auth (1.4)
26
- net-http-persistent (2.9.4)
27
- nokogiri (1.6.7.2)
28
- mini_portile2 (~> 2.0.0.rc2)
29
- ntlm-http (0.1.1)
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
- unf (0.1.4)
32
- unf_ext
33
- unf_ext (0.0.7.2)
34
- webrobots (0.1.2)
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.11.2
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
- ThuStudent.profile('學號','密碼')
27
- ```
30
+ student = ThuStudent.new('student_id','password')
28
31
 
29
- 取得個人成績總表
32
+ student.profile
33
+ #profile 個人資料
30
34
 
31
- ```ruby
32
- ThuStudent.transcript('學號','密碼')
35
+ student.course_info
36
+ #course_info 學程資訊
37
+
38
+ student.course
39
+ #course 歷年修課紀錄
33
40
  ```
34
41
 
35
42
  ## Development
@@ -1,73 +1,112 @@
1
1
  require 'thu_student/version'
2
- require 'mechanize'
3
- module ThuStudent
4
- def self.profile(username, password)
5
- agent = Mechanize.new
6
- page = agent.get('http://fsis.thu.edu.tw/mosi/ccsd3/ccsd3_gen.php?job=stud&loginn=Y')
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
- l_page = form.submit.body.split('n="').last.split('";').first
13
- agent.get("http://fsiso.thu.edu.tw#{l_page}")
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
- profiles = agent.get('http://fsiso.thu.edu.tw/wwwstud/STUD_V6/INFO/MyProfile.php?job=personinfo')
18
+ attr_reader :profile
19
+ attr_reader :course_info
20
+ attr_reader :course
16
21
 
17
- profiles = profiles.search('table tbody tr td')
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
- student_id = profiles[0].text.split(":").last
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
- hash = []
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
- hash << { student_id: student_id, name: name, sex: sex, birthday: birthday, id: id, type: type, grade: grade, identity: identity, country: country, status: status, guardian: guardian, home_address: home_address, home_phone: home_phone, address: address, use_phone: use_phone, teltphone: telephone }
64
+ profile_data
43
65
  end
44
66
 
45
- def self.transcript(username, password)
46
- agent = Mechanize.new
47
- page = agent.get('http://fsis.thu.edu.tw/mosi/ccsd3/ccsd3_gen.php?job=stud&loginn=Y')
48
- form = page.forms.first
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
- form['username'] = username
51
- form['passwd'] = password
77
+ course_info_data
78
+ end
52
79
 
53
- l_page = form.submit.body.split('n="').last.split('";').first
54
- agent.get("http://fsiso.thu.edu.tw#{l_page}")
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
- transcripts = agent.get('http://fsiso.thu.edu.tw/wwwstud/STUD_V6/COURSE/rcrd_all.php')
88
+ course_data
89
+ end
57
90
 
58
- transcripts = transcripts.search('#no-more-tables tbody tr')
59
- hash = []
60
- transcripts.each do |transcript|
61
- transcript = transcript.search('td')
62
- year = transcript[0].text
63
- semester = transcript[1].text
64
- course_id = transcript[2].text
65
- name = transcript[3].text
66
- credit = transcript[4].text
67
- score = transcript[5].text
68
- hash << { year: year, semester: semester, course_id: course_id, name: name, credit: credit, score: score }
69
- end
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
- hash
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
@@ -1,3 +1,4 @@
1
- module ThuStudent
2
- VERSION = '0.1.1'.freeze
1
+ # frozen_string_literal: true
2
+ class ThuStudent
3
+ VERSION = '0.1.2'.freeze
3
4
  end
@@ -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 "mechanize" , "~> 2.7.0"
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.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: 2016-06-14 00:00:00.000000000 Z
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: mechanize
42
+ name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.7.0
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: 2.7.0
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: []
Binary file