arb-xmu-course 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 033892d7b5333bf00107dbfec09930a09e51d68d
4
- data.tar.gz: 6ab649181d6263af37af3248b21084e679b8a28c
3
+ metadata.gz: 95c02ba43fd8cff44bd99d0992f983f4be15b0a3
4
+ data.tar.gz: 1fe1077cff0959c77facb0d390bc2ceb7d7c8278
5
5
  SHA512:
6
- metadata.gz: bef7169c325840623e5af693600a9b694614dc54791185647a343d08bd761290e2e8f1949e705976821b2389028de7320a7e5ebb091bbe7eca7e73f3302b2ade
7
- data.tar.gz: 0a02725936ec1a99a09fff4ca0b61704cd1a97309c482a875ffe9075025ff3df7f6ecf6c095665673c34442cf68fa82d5e05eb6091d0db5fc167d906830d8557
6
+ metadata.gz: f83d157aed86f3291b09dd02f4d977fc71a65b7488577f73f85edd0adc5be632acea93ed9485d444b1f005b4f3a959b8a269d02f18a0bcf2c4e0bfcc8aa3a42c
7
+ data.tar.gz: 66fdacc1923b13469499aa558da1e6fa17ba168b0c26ac004559c98bacd0ccf0aba84ccc4e5886cf01eb956131d549167510e767e3dda8257e6e4c14d8aedd4c
data/bin/arb-xmu-course CHANGED
@@ -11,6 +11,7 @@ include Arb::Xmu::Course
11
11
 
12
12
  TOKEN_FILE_NAME = 'encrypted_token'
13
13
  TOKEN_SEPARATOR = ':'
14
+ CLIENT = HTTPClient.new
14
15
 
15
16
 
16
17
  def filter_text(raw)
@@ -112,74 +113,82 @@ def request_select_course(client, course_entity, xxlx, lcid)
112
113
  JSON::parse msg.body
113
114
  end
114
115
 
115
- def create_attempt_thread(max_interval, client, course_entity, xxlx, lcid)
116
- Thread.new do
116
+ def create_attempt_thread(max_interval, client, course, xxlx, lcid, &block)
117
+ Thread.new do
117
118
  count=0
118
119
  loop do
119
120
  count+=1
120
- interval = 1+rand(max_interval)
121
+ interval= 1+rand(max_interval)
121
122
  sleep interval
122
- res = request_select_course(client, course_entity, xxlx, lcid)
123
- if res[:success]
124
- $stdout.puts "课程:《#{course_entity.name}》已经成功选课!"
123
+ res = request_select_course(client, course, xxlx, lcid)
124
+ if res['success']
125
+ $stdout.puts "课程:《#{course.name}》已经成功选课!"
125
126
  break
126
127
  else
127
- $stdout.puts "课程:《#{course_entity.name}》第#{count}次尝试选课失败,#{interval}秒后将重试。"
128
+ $stdout.puts "课程:《#{course.name}》第#{count}次尝试选课失败,#{interval}秒后将重试。(错误信息:#{res['message']})"
128
129
  end
130
+ exit if block.binding.local_variable_get(:opened_thread_count)-1==0
129
131
  end
130
-
131
132
  end
132
133
  end
133
134
 
134
-
135
- def select_school_elective(client, username, password)
135
+ def prepare_select_course(client)
136
+ ensure_account
137
+ username, password = get_account_info
136
138
  authorize_session(client, username, password)
137
- lcid=get_main_select_round(client)
138
-
139
- school_courses = parse_courses((client.get 'http://bkxk.xmu.edu.cn/xsxk/yxxx.html').body)
140
- show_courses_in_table school_courses
139
+ end
141
140
 
142
- $stdout.puts
141
+ def try_to_select_courses(client, courses, xxlx, lcid)
142
+ $stdout.puts ''
143
143
  $stdout.puts '输入要选的课程ID, 以空格分割:'
144
144
 
145
145
  ids = $stdin.gets.chomp.split(' ')
146
146
 
147
- $stdout.puts '输入最大重试间隔时间,默认3秒,要求不得低于2秒:'
147
+ $stdout.puts '输入最大重试间隔时间,要求不得低于2秒:'
148
148
 
149
149
  max_interval = $stdin.gets.chomp.to_i
150
150
  max_interval = 2 if max_interval<2
151
-
151
+ opened_thread_count = ids.size
152
152
  ids.each do |id|
153
- create_attempt_thread(max_interval, client, school_courses.find { |course| course.index==id.to_i }, 1, lcid)
153
+ create_attempt_thread(max_interval, client, courses.find { |course| course.index==id.to_i }, xxlx, lcid) {}
154
154
  end
155
+ end
155
156
 
156
- loop do
157
- sleep 3
157
+ def get_account_info
158
+ stu_id, passwd=nil
159
+ File.open TOKEN_FILE_NAME, 'r' do |file|
160
+ stu_id, passwd=SimpleDes.decrypt(file.read.split(TOKEN_SEPARATOR))
158
161
  end
162
+ [stu_id, passwd]
163
+ end
159
164
 
160
165
 
161
- end
166
+ def select_school_elective(client)
162
167
 
163
- def select_general_elective
168
+ prepare_select_course(client)
169
+ school_courses = parse_courses((client.get 'http://bkxk.xmu.edu.cn/xsxk/yxxx.html').body)
170
+ show_courses_in_table school_courses
171
+ try_to_select_courses(client, school_courses, 4, get_main_select_round(client))
164
172
 
173
+ loop do
174
+ sleep 3
175
+ end
165
176
  end
166
177
 
167
- def select_public
178
+ def select_general_elective
168
179
 
169
180
  end
170
181
 
182
+ def select_public
171
183
 
172
- unless (File.exists? TOKEN_FILE_NAME)
173
- puts '请先设置账户信息(账户信息会先加密然后保存在本地,用于授权选课系统)'
174
- set_up_account
175
- exit
176
184
  end
177
185
 
178
- stu_id, passwd=nil
179
- client = HTTPClient.new
180
-
181
- File.open TOKEN_FILE_NAME, 'r' do |file|
182
- stu_id, passwd=SimpleDes.decrypt(file.read.split(TOKEN_SEPARATOR))
186
+ def ensure_account
187
+ unless (File.exists? TOKEN_FILE_NAME)
188
+ puts '请先设置账户信息(账户信息会先加密然后保存在本地,用于授权选课系统)'
189
+ set_up_account
190
+ exit
191
+ end
183
192
  end
184
193
 
185
194
  opts = Slop.parse do |o|
@@ -188,14 +197,18 @@ opts = Slop.parse do |o|
188
197
  o.bool *%w{-r --reset}, '重置账户信息'
189
198
 
190
199
  #院选课程 xxlx=4
191
- o.bool *%w{-s --school}, '院选选课'
200
+ o.bool *%w{-s --school}, '院选选课模式'
192
201
  #校选课程 xxlx=3
193
- o.bool *%w{-g --general}, '校选选课'
202
+ o.bool *%w{-g --general}, '校选选课模式'
194
203
  #公共课程 xxlx=5
195
- o.bool *%w{-p --public}, '公共课选课'
204
+ o.bool *%w{-p --public}, '公共课选课模式'
205
+
206
+ o.bool *%w{-v --version}, '显示当前版本'
196
207
  end
197
208
 
198
209
  case true
210
+ when opts.version?
211
+ puts Arb::Xmu::Course::VERSION
199
212
  when opts.help?
200
213
  puts(opts) && exit
201
214
  when opts.clear?
@@ -203,34 +216,11 @@ case true
203
216
  when opts.reset?
204
217
  set_up_account && exit
205
218
  when opts.school?
206
- select_school_elective(client, stu_id, passwd)
219
+ select_school_elective(CLIENT)
207
220
  when opts.general?
208
221
  # select_general_elective
209
222
  when opts.public?
210
223
  # select_public
211
- end
212
-
213
- # client = HTTPClient.new
214
-
215
- # #session init
216
- # client.get 'http://bkxk.xmu.edu.cn/xsxk/login.html'
217
- #
218
- # File.open 'checkcode.jpeg','wb' do |file|
219
- # file.write(client.get('http://bkxk.xmu.edu.cn/xsxk/getCheckCode').body)
220
- # end
221
- #
222
- # puts 'enter your student id'
223
- # user= gets.chomp
224
- # puts 'enter your password'
225
- # passwd=gets.chomp
226
- # puts 'enter the checkcode'
227
- # checkcode=gets.chomp
228
- #
229
- # client.get 'http://bkxk.xmu.edu.cn/xsxk/login.html',username: user,password: passwd,checkCode: checkcode
230
- #
231
- # puts (client.get 'http://bkxk.xmu.edu.cn/xsxk/localInfo.html').body
232
- #
233
- # Nokogiri::parse((client.get 'http://bkxk.xmu.edu.cn/xsxk/index.html').body).css('script').each do |x|
234
- # puts x.text
235
- # end
236
- #
224
+ else
225
+ puts(opts) && exit
226
+ end
data/bin/check_code.jpeg CHANGED
Binary file
@@ -5,7 +5,7 @@ module Arb
5
5
  module Util
6
6
  class SimpleDes
7
7
  ALG = 'DES-EDE3-CBC'
8
- KEY = (Dir.pwd.split('').select { |char| char=~/\w/ }.join+'bYaRyBin')[0..7]
8
+ KEY = 'bYaRyBin'
9
9
  DES_KEY = KEY.swapcase
10
10
  class << self
11
11
  %i{encrypt decrypt}.each do |type|
@@ -1,7 +1,7 @@
1
1
  module Arb
2
2
  module Xmu
3
3
  module Course
4
- VERSION = '1.0.0'
4
+ VERSION = '1.2.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arb-xmu-course
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arybin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-22 00:00:00.000000000 Z
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler