arb-xmu-course 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/arb-xmu-course +45 -23
- data/lib/arb/xmu/course/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad79bdaebc016960dc856a9bbac2758a2fadf00e
|
4
|
+
data.tar.gz: d717f48f46109f8f683dc90879cab3d88ec286c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c2cfe9ced779a47efd2e5afba8b9018d36c15e294af4182f49dcca43f7931ebb474c7e4e743c105475dfdda63f3182de3bbd386a092a69e175fcfa6c80137b9
|
7
|
+
data.tar.gz: 3422450527621467757d33baf1e010cfc390ff0dd00599da2d4bbf541bc285f8205a82b78ec0614d5164a37f2b567db4f19b35fec6ccd9d08477e7ec1a318359
|
data/bin/arb-xmu-course
CHANGED
@@ -42,6 +42,8 @@ def select_course_common(client, url, xxlx)
|
|
42
42
|
loop do
|
43
43
|
global_gets
|
44
44
|
end
|
45
|
+
rescue Timeout::Error, HTTPClient::TimeoutError
|
46
|
+
exit_with_error "服务器无响应,程序结束运行。"
|
45
47
|
end
|
46
48
|
|
47
49
|
def set_up_account
|
@@ -118,24 +120,33 @@ def parse_courses(raw_html)
|
|
118
120
|
courses.select { |course| course.id.size>0 }
|
119
121
|
end
|
120
122
|
|
121
|
-
def create_attempt_thread(max_interval, client, course, xxlx, lcid, &block)
|
123
|
+
def create_attempt_thread(max_interval, client, course, xxlx, lcid, retry_count, &block)
|
122
124
|
Thread.new do
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
125
|
+
begin
|
126
|
+
count=0
|
127
|
+
loop do
|
128
|
+
count+=1
|
129
|
+
interval= 1+rand(max_interval)
|
130
|
+
begin
|
131
|
+
res = request_select_course(client, course, xxlx, lcid)
|
132
|
+
if res['success']
|
133
|
+
global_puts "《#{course.name}》(#{course.class_name}班)已经成功选课!"
|
134
|
+
break
|
135
|
+
else
|
136
|
+
global_puts "《#{course.name}》(#{course.class_name}班)第#{count}次尝试选课失败,#{interval}秒后将重试。(#{filter_text(res['message'])})"
|
137
|
+
end
|
138
|
+
sleep interval
|
139
|
+
rescue Timeout::Error, HTTPClient::TimeoutError
|
140
|
+
retry if retry_count!=0 and retry_count-=1 and global_puts('网络超时,重新连接中……')
|
141
|
+
exit_with_error('超时次数耗尽,程序结束运行。') if retry_count==0
|
142
|
+
end
|
133
143
|
end
|
134
|
-
|
144
|
+
opened_thread_count=block.binding.local_variable_get(:opened_thread_count)
|
145
|
+
exit unless opened_thread_count > 0
|
146
|
+
block.binding.local_variable_set :opened_thread_count, opened_thread_count-1
|
147
|
+
rescue
|
148
|
+
exit_with_error('未知原因导致程序运行出错,请联系作者。')
|
135
149
|
end
|
136
|
-
opened_thread_count=block.binding.local_variable_get(:opened_thread_count)
|
137
|
-
exit unless opened_thread_count > 0
|
138
|
-
block.binding.local_variable_set :opened_thread_count, opened_thread_count-1
|
139
150
|
end
|
140
151
|
end
|
141
152
|
|
@@ -171,7 +182,7 @@ def try_to_select_courses(client, courses, xxlx, lcid)
|
|
171
182
|
max_interval = 3 if max_interval<3
|
172
183
|
opened_thread_count = ids.size
|
173
184
|
ids.each do |id|
|
174
|
-
create_attempt_thread(max_interval, client, courses.find { |course| course.index==id }, xxlx, lcid) {}
|
185
|
+
create_attempt_thread(max_interval, client, courses.find { |course| course.index==id }, xxlx, lcid, $arb_retry_count) {}
|
175
186
|
end
|
176
187
|
end
|
177
188
|
|
@@ -224,11 +235,12 @@ def filter_text(raw)
|
|
224
235
|
end
|
225
236
|
|
226
237
|
def global_puts(*args)
|
227
|
-
fileout=File.open($
|
238
|
+
fileout=File.open($arb_logfile,'a') if $arb_logfile
|
228
239
|
[fileout,$stdout].compact.each do |stream|
|
229
|
-
stream.puts
|
240
|
+
stream.puts Time.now,*args,''
|
230
241
|
end
|
231
|
-
fileout.close rescue
|
242
|
+
fileout.close rescue true
|
243
|
+
true
|
232
244
|
end
|
233
245
|
|
234
246
|
def global_gets(*args)
|
@@ -238,19 +250,25 @@ def global_gets(*args)
|
|
238
250
|
tmp
|
239
251
|
end
|
240
252
|
|
253
|
+
def exit_with_error(*args)
|
254
|
+
global_puts(*args) and exit
|
255
|
+
end
|
256
|
+
|
241
257
|
|
242
258
|
TOKEN_FILE_NAME = 'encrypted_token'
|
243
259
|
TOKEN_SEPARATOR = ':'
|
244
260
|
CLIENT = HTTPClient.new
|
261
|
+
CLIENT.tap{|client| client.methods.grep(/timeout=$/).each{|method| client.send(method,20)}}
|
245
262
|
|
246
263
|
begin
|
247
264
|
opts = Slop.parse do |o|
|
248
|
-
o.banner="
|
265
|
+
o.banner="为缓解选课服务器压力,请酌情选择较大的“最大重试间隔”。在任何需要输入的地方输入“q”或“quit”可以结束本程序。 --Powered By AryBin"
|
249
266
|
|
250
267
|
o.bool *%w{-h --help}, '显示帮助'
|
251
268
|
o.bool *%w{-c --clear}, '清除本地账户信息'
|
252
269
|
o.bool *%w{-r --reset}, '重置账户信息'
|
253
270
|
o.string *%w{-l --log},'记录到指定的日志文件'
|
271
|
+
o.integer *%w{-R --retry-count},'超时重连次数,默认无限次'
|
254
272
|
|
255
273
|
#院选课程 xxlx=4
|
256
274
|
o.bool *%w{-s --school}, '院选选课模式'
|
@@ -268,14 +286,18 @@ begin
|
|
268
286
|
o.bool *%w{-v --version}, '显示当前版本'
|
269
287
|
end
|
270
288
|
rescue Slop::MissingArgument
|
271
|
-
|
289
|
+
exit_with_error '参数不足,请确认。'
|
272
290
|
rescue Slop::UnknownOption
|
273
|
-
|
291
|
+
exit_with_error '未知选项,请确认。'
|
292
|
+
rescue
|
274
293
|
end
|
275
294
|
|
276
295
|
#error
|
277
296
|
exit unless opts
|
278
|
-
$
|
297
|
+
$arb_logfile = opts[:log]
|
298
|
+
$arb_retry_count = opts[:'retry-count'] or -1
|
299
|
+
global_puts '参数解析完毕,连接服务器……'
|
300
|
+
|
279
301
|
|
280
302
|
case true
|
281
303
|
when opts.clear?
|
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: 2.
|
4
|
+
version: 2.5.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-
|
11
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|