arb-xmu-course 1.2.1 → 2.0.0

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: 1ea9805a0a962e812c6401616c1144f41bad7d91
4
- data.tar.gz: d54afdb50f4d0a7abb0d9eecf1a1e7f675e8506a
3
+ metadata.gz: e85f64acb48eb553e908353453ac7e976cad47d6
4
+ data.tar.gz: 74bcb5fbc624ad94e17a454676fbfe722f11a9d7
5
5
  SHA512:
6
- metadata.gz: 04533927f412c01fef853fb082f334cc25d0bce8ba044619102ef6696ae4c689ea3b2fdc58ac460063dd5796348d997f488767f85f21bd62d6640527e2a22e58
7
- data.tar.gz: a55d52b58c144f6189bb0c597d85f8491198c099b62acfec8c1a813b0a51c024b8c4e4eb0ff3a6aecfbb0c0c7d6e6d1502ee9952e4597581c1b5838f30cb8fdc
6
+ metadata.gz: 9451ef7d6f5710ecf9eb25544a690a65a4b6c972bee897eac0de1feea3b5ec0a1ecf974dc3ca40fcd6bc38550f029d034f09b22c75ad30a1ae79de14e68ea25c
7
+ data.tar.gz: 3d59a5b48c0221a22976b296fd51bdacb36626dd0af1b56d7138d6d6bf3c7ab04116b87edd0c5a32581dc8e6ed3f4623d65a4c6de809dcf3f5f632215ead7a5d
data/bin/arb-xmu-course CHANGED
@@ -22,7 +22,7 @@ def filter_text(raw)
22
22
  end
23
23
  end
24
24
  end
25
- black_list =([] << "\r" << "\n" << "\t" << "'")
25
+ black_list =([] << "\r" << "\n" << "\t" << "'" << '<br>')
26
26
  black_list.each do |tmp|
27
27
  raw.gsub! tmp, ''
28
28
  end
@@ -122,10 +122,10 @@ def create_attempt_thread(max_interval, client, course, xxlx, lcid, &block)
122
122
  sleep interval
123
123
  res = request_select_course(client, course, xxlx, lcid)
124
124
  if res['success']
125
- $stdout.puts "课程:《#{course.name}》已经成功选课!"
125
+ $stdout.puts '', "课程:《#{course.name}》已经成功选课!", ''
126
126
  break
127
127
  else
128
- $stdout.puts "课程:《#{course.name}》第#{count}次尝试选课失败,#{interval}秒后将重试。(错误信息:#{res['message']})"
128
+ $stdout.puts '', "课程:《#{course.name}》第#{count}次尝试选课失败,#{interval}秒后将重试。(错误信息:#{filter_text(res['message'])})", ''
129
129
  end
130
130
  exit if block.binding.local_variable_get(:opened_thread_count)-1==0
131
131
  end
@@ -133,24 +133,29 @@ def create_attempt_thread(max_interval, client, course, xxlx, lcid, &block)
133
133
  end
134
134
 
135
135
  def prepare_select_course(client)
136
- ensure_account
136
+ ensure_local_account
137
137
  username, password = get_account_info
138
138
  authorize_session(client, username, password)
139
139
  end
140
140
 
141
- def try_to_select_courses(client, courses, xxlx, lcid)
142
- $stdout.puts ''
143
- $stdout.puts '输入要选的课程ID, 以空格分割:'
144
-
145
- ids = $stdin.gets.chomp.split(' ')
146
-
147
- $stdout.puts '输入最大重试间隔时间,要求不得低于2秒:'
141
+ def process_ids(str_ids)
142
+ #return int_ids
143
+ int_ids = str_ids.map do |item|
144
+ next item.to_i unless item=~/[^0-9]/
145
+ next (Range.new *(item.split('-').map(&:to_i))).to_a if item.include? '-'
146
+ end
147
+ int_ids.flatten.uniq
148
+ end
148
149
 
150
+ def try_to_select_courses(client, courses, xxlx, lcid)
151
+ $stdout.puts '', '输入要选的课程ID(重复无效,支持语法糖:x-y,会尝试选择ID从x到y的所有课程), 以空格分割:'
152
+ ids = process_ids($stdin.gets.chomp.split(' '))
153
+ $stdout.puts '输入最大重试间隔时间,要求不得低于3秒:'
149
154
  max_interval = $stdin.gets.chomp.to_i
150
- max_interval = 2 if max_interval<2
155
+ max_interval = 3 if max_interval<3
151
156
  opened_thread_count = ids.size
152
157
  ids.each do |id|
153
- create_attempt_thread(max_interval, client, courses.find { |course| course.index==id.to_i }, xxlx, lcid) {}
158
+ create_attempt_thread(max_interval, client, courses.find { |course| course.index==id }, xxlx, lcid) {}
154
159
  end
155
160
  end
156
161
 
@@ -160,34 +165,37 @@ def get_account_info
160
165
  stu_id, passwd=SimpleDes.decrypt(file.read.split(TOKEN_SEPARATOR))
161
166
  end
162
167
  [stu_id, passwd]
168
+ rescue
169
+ puts '账号信息受损,请重新设置:'
170
+ set_up_account && exit
163
171
  end
164
172
 
165
-
166
- def select_school_elective(client)
167
-
173
+ def select_course_common(client, url, xxlx)
168
174
  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))
172
-
175
+ courses = parse_courses((client.get url).body)
176
+ show_courses_in_table courses
177
+ try_to_select_courses(client, courses, xxlx, get_main_select_round(client))
173
178
  loop do
174
179
  sleep 3
175
180
  end
176
181
  end
177
182
 
178
- def select_general_elective
179
-
183
+ def select_school_elective(client)
184
+ select_course_common client, 'http://bkxk.xmu.edu.cn/xsxk/yxxx.html?pagination=5000', 4
180
185
  end
181
186
 
182
- def select_public
187
+ def select_general_elective(client)
188
+ select_course_common client, 'http://bkxk.xmu.edu.cn/xsxk/qxxxx.html?pagination=5000', 3
189
+ end
183
190
 
191
+ def select_public(client)
192
+ select_course_common client, 'http://bkxk.xmu.edu.cn/xsxk/ggk.html?pagination=5000', 5
184
193
  end
185
194
 
186
- def ensure_account
195
+ def ensure_local_account
187
196
  unless (File.exists? TOKEN_FILE_NAME)
188
- puts '请先设置账户信息(账户信息会先加密然后保存在本地,用于授权选课系统)'
189
- set_up_account
190
- exit
197
+ puts '请先设置账号信息(账号信息会先加密然后保存在本地,用于授权选课系统)'
198
+ set_up_account && exit
191
199
  end
192
200
  end
193
201
 
@@ -218,9 +226,9 @@ case true
218
226
  when opts.school?
219
227
  select_school_elective(CLIENT)
220
228
  when opts.general?
221
- # select_general_elective
229
+ select_general_elective(CLIENT)
222
230
  when opts.public?
223
- # select_public
231
+ select_public(CLIENT)
224
232
  else
225
233
  puts(opts) && exit
226
234
  end
data/bin/check_code.jpeg CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  module Arb
2
2
  module Xmu
3
3
  module Course
4
- VERSION = '1.2.1'
4
+ VERSION = '2.0.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arb-xmu-course
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arybin