forked from SnoozeZ/seu-jwc-fker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Evaluate.py
650 lines (582 loc) · 26.3 KB
/
Evaluate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# coding: utf-8
########################################################################
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar <[email protected]>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
########################################################################
# if you want to pack it up into EXE, Mind that you got to
# do .encode after str
import urllib.parse
import urllib.request, urllib.parse, urllib.error
import http.cookiejar
import re
import time
import numpy as np
import os
import cv2
import SEU_Decode_CNN
import URL2IMG
cnt = 0
total = 0
WantedLessonsNameList = []
def getTrainData(img, code, text):
if text.find('尚未开放') != -1: # would this make it more unfair to others?
if cv2.imwrite("E:/Python_Project/Python3.6/SEU_LES_CATCHER/TrainData/" + code + ".jpg", img) == True:
global cnt
cnt += 1
print(str(cnt) + "训练数据已保存")
if (cnt >= 1200):
quit()
def EvaluateModel(text):
global total
total += 1
if text.find('尚未开放') != -1:
global cnt
cnt += 1
print("识别正确")
else:
print("识别错误")
if (total >= 200):
print("验证码识别成功率 %d %%" % (int(cnt / total * 100)))
quit()
def loginIn(userName, passWord, inputCaptcha=False):
# 设置cookie处理器
cj = http.cookiejar.LWPCookieJar()
cookie_support = urllib.request.HTTPCookieProcessor(cj)
opener = urllib.request.build_opener(cookie_support, urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
# 打开选课页面
# h = urllib2.urlopen('http://xk.urp.seu.edu.cn/jw_css/system/showLogin.action', timeout = 10) # seems it is not necessary
# 获取验证码
for i in range(10):
try:
CodeImg = URL2IMG.url_to_image('http://xk.urp.seu.edu.cn/jw_css/getCheckCode')
break
except Exception as e:
print(e)
continue
else:
return (False, "验证码获取失败", '')
if inputCaptcha == True: # manually input the capthcha
# 读取验证码
# code = raw_input(u'请打开我所在目录下的code.jpg,并在这里敲入里面的四位数字验证码:')
code = input('请打开我所在目录下的code.jpg,并在这里敲入里面的四位数字验证码:') # used for exporting to exe
else: # automatically recognise the captcha
code = SEU_Decode_CNN.SEU_Decode(CodeImg)
# 构造post数据
posturl = 'http://xk.urp.seu.edu.cn/jw_css/system/login.action'
header = {
'Host': 'xk.urp.seu.edu.cn',
'Proxy-Connection': 'keep-alive',
'Origin': 'http://xk.urp.seu.edu.cn',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
'Referer': 'http://xk.urp.seu.edu.cn/jw_css/system/login.action'
}
data = {
'userId': userName,
'userPassword': passWord, # 你的密码,
'checkCode': code, # 验证码
'x': '33', # 别管
'y': '5' # 别管2
}
# post登录数据
(state, text) = postData(posturl, header, data)
url = ''
if state == True:
if (text.find('选课批次') != -1): # a bad label; the url returned should be the best
print("登录成功")
function = re.search(r'onclick="changeXnXq.*\)"', text); # find the function whose parameter are desired
function = function.group()
parameters = re.search(r"'(.*)','(.*)','(.*)'\)", function) # fetch url parameters
url = "http://xk.urp.seu.edu.cn/jw_css/xk/runXnXqmainSelectClassAction.action?Wv3opdZQ89ghgdSSg9FsgG49koguSd2fRVsfweSUj=Q89ghgdSSg9FsgG49koguSd2fRVs&selectXn=" + parameters.group(
1) + "&selectXq=" + parameters.group(2) + "&selectTime=" + parameters.group(3)
else:
state = False
errorMessage = re.search(r'id="errorReason".*?value="(.*?)"', text)
text = errorMessage.group(1)
# getTrainData(CodeImg,code,text)
EvaluateModel(text)
else:
text = "网络错误,登录失败"
return (state, text, url)
def selectSemester(semesterNum, url):
print("切换学期菜单中......")
time.sleep(5)
# 构造选择学期的包
# !!!NOTICE: SELECTTIME manually set this url is not a wise choice
# geturl ='http://xk.urp.seu.edu.cn/jw_css/xk/runXnXqmainSelectClassAction.action?Wv3opdZQ89ghgdSSg9FsgG49koguSd2fRVsfweSUj=Q89ghgdSSg9FsgG49koguSd2fRVs&selectXn=2014&selectXq='+str(semesterNum)+'&selectTime=2014-05-30%2013:30~2014-06-07%2023:59'
geturl = re.sub('selectXq=.', 'selectXq=' + str(semesterNum), url)
header = {'Host': 'xk.urp.seu.edu.cn',
'Proxy-Connection': 'keep-alive',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
}
data = {}
# get获取学期课程
(state, text) = getData(geturl, header, data)
if state == True:
if text.find("数据异常") != -1: # switched to an unavailable semester
state = False
text = "目前无法选择学期" + str(semesterNum)
return (state, text)
def postData(posturl, headers, postData):
postData = urllib.parse.urlencode(postData).encode("utf-8") # Post数据编码
request = urllib.request.Request(posturl, postData, headers) # 通过urllib2提供的request方法来向指定Url发送我们构造的数据,并完成登录过程
text = ''
for i in range(10):
try:
response = urllib.request.urlopen(request, timeout=5)
text = response.read()
break
except HTTPError as e:
print("The server couldn't fulfill the request.")
# print('Error code: ', e.code)
except URLError as e:
print('We failed to reach a server.')
# print('Reason: ', e.reason)
else:
print("good!")
# print(response.read().decode("utf8"))
continue
else:
return (False, "数据发送失败")
return (True, text.decode("utf-8"))
def getData(geturl, header, getData, returnUrl=False):
getData = urllib.parse.urlencode(getData).encode("utf-8")
request = urllib.request.Request(geturl, getData, header)
text = ''
url = ''
for i in range(10):
try:
response = urllib.request.urlopen(request, timeout=5)
text = response.read()
url = response.geturl()
break
except Exception as e:
print(e)
print('trying to open agian...')
continue
else:
if returnUrl == False:
return (False, "获取数据失败")
else:
return (False, "获取数据失败", '')
if returnUrl == False:
return (True, text.decode("utf-8"))
else:
return (True, text.decode("utf-8"), url)
def stateCheck(textValue):
text = textValue
if (text.find('成功选择') != -1) or (text.find('服从推荐') != -1):
return 0
if text.find('已满') != -1:
return 1
if text.find('失败') != -1:
return 2
def Mode1(semesterNum, url):
(state, text) = selectSemester(semesterNum, url)
if state == False:
print(text)
print('切换到学期' + str(semesterNum) + "失败")
return
else:
print('切换到学期' + str(semesterNum) + "成功")
# 寻找可以“服从推荐”的课程
print("==============\n模式1,开始选课\n==============")
courseList = []
pattern = re.compile(r'\" onclick=\"selectThis\(\'.*\'')
pattern2 = re.compile(r'id=\".*\" align=\"center\"\>.*\n.*\<font class=\"style2\"\>')
pos = 0
m = pattern.search(text, pos)
pos2 = 0
m2 = pattern2.search(text, pos2)
courseNameList = []
while m:
pos = m.end()
tempText = m.group()
m2 = pattern2.search(text, 0)
tempText2 = m2.group()
parameters = re.search(r"selectThis\('(.*?)','(.*?)','(.*?)'", tempText)
parameters2 = re.search(
r'id=\"' + parameters.group(1) + '\" align=\"center\"\>.*\n.*\<font class=\"style2\"\>(.*?)\<', text)
courseNameList.append(parameters2.group(1))
course = [parameters.group(1), parameters.group(2), parameters.group(3), 1]
courseList.append(course)
m = pattern.search(text, pos) # 寻找下一个
times = 0
success = 0
total = len(courseList)
for courseNames in courseNameList:
print(courseNameList.index(courseNames) + 1, courseNames)
# print courseNameList.index(courseNames) + 1, courseNames
ManualChoose = True
WantedLessons = np.zeros(total)
if len(WantedLessonsNameList) > 0:
ManualChoose = False
for courseNames in courseNameList:
for WantedLes in WantedLessonsNameList:
if courseNames.find(WantedLes) != -1:
WantedLessons[courseNameList.index(courseNames)] = 1
print("读取本地文件后,当前将要选择的课程是\n")
for id, isWanted in enumerate(WantedLessons):
if (isWanted):
print(courseNameList[id])
ManChoose = input("是否要继续选择? [n]/y:")
if ManChoose == 'y' or ManChoose == 'Y': # should other cases be considered?
ManualChoose = True
if ManualChoose:
while True:
# WantedLessonsID=input(u'\n请输入需要的课程(输入0结束选择,输入-1选择全部):')
WantedLessonsID = eval(input('\n请输入需要的课程(输入0结束选择,输入-1选择全部):'))
if (WantedLessonsID == 0):
break
if (WantedLessonsID == -1):
WantedLessons = np.ones(total)
break
WantedLessons[WantedLessonsID - 1] = 1
while True:
if total == 0:
print("目前没有课可以选择")
break
time.sleep(0.8) # sleeps +1
times = times + 1
print("\n第" + str(times) + "次选课,已成功选择" + str(success) + "门")
for course in courseList:
if course[3] == 1 and WantedLessons[courseList.index(course)]:
# 构造选课post
print("正在选择课程" + courseNameList[courseList.index(course)])
posturl = 'http://xk.urp.seu.edu.cn/jw_css/xk/runSelectclassSelectionAction.action?select_jxbbh=' + \
course[1] + '&select_xkkclx=' + course[2] + '&select_jhkcdm=' + course[0]
headers = {'Host': 'xk.urp.seu.edu.cn',
'Proxy-Connection': 'keep-alive',
'Content-Length': '2',
'Accept': 'application/json, text/javascript, */*',
'Origin': 'http://xk.urp.seu.edu.cn',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
}
data = {'{}': ''
}
# post选课包,并获取返回状态
(state, text) = postData(posturl, headers, data)
if state == False:
text = '网络错误'
else:
if text.find('isSuccess":"false') != -1:
state = False
text = re.search(r'errorStr":"(.*?)"', text).group(1)
if state == True:
course[3] = 0
success += 1
total -= 1
print("Nice, 课程" + courseNameList[courseList.index(course)] + " 选择成功")
else:
print("课程" + courseNameList[courseList.index(course)] + " 选课失败," + text)
def Mode2(semesterNum, courseName, url):
(state, text) = selectSemester(semesterNum, url)
if state == False:
print(text.decode('utf-8'))
print('切换到学期' + str(semesterNum) + "失败")
return
else:
print('切换到学期' + str(semesterNum) + "成功")
print("==============\n模式2,开始选课\n==============")
# 获取人文课页面
geturl1 = 'http://xk.urp.seu.edu.cn/jw_css/xk/runViewsecondSelectClassAction.action?select_jhkcdm=00034&select_mkbh=rwskl&select_xkkclx=45&select_dxdbz=0'
header1 = {
'Host': 'xk.urp.seu.edu.cn',
'Proxy-Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
}
data1 = {}
(state, text) = getData(geturl1, header1, data1)
if state == False:
print("打开课程列表页面失败")
return
# 构造RE
# print text
pattern = (courseName + '.*?(\"8%\" id=\"(.{0,20})\" align)') # possible problem here??
# 获取课程编号
courseNo = re.findall(pattern, text, re.S)[0][1]
# 构造数据包
posturl = 'http://xk.urp.seu.edu.cn/jw_css/xk/runSelectclassSelectionAction.action?select_jxbbh=' + courseNo + '&select_xkkclx=45&select_jhkcdm=00034&select_mkbh=rwskl'
headers = {
'Host': 'xk.urp.seu.edu.cn',
'Proxy-Connection': 'keep-alive',
'Content-Length': '2',
'Accept': 'application/json, text/javascript, */*',
'Origin': 'http://xk.urp.seu.edu.cn',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
}
data = {
'{}': ''
}
print("我开始选课了,课程编号:" + courseNo)
times = 0
while True:
# 判断是否选到课
times = times + 1
(state, text) = getData(geturl1, header1, data1)
if state == False:
print("打开课程列表页面失败")
return
pattern2 = ('已选(.{0,200})align=\"')
result = re.findall(pattern2, text, re.S)
# print result
success = len(result) # 为0为不成功 继续
if (success != 0) and (result[0].find(courseNo) != -1):
print("Nice,已经选到课程:" + courseNo)
break
# 发送选课包
print("第" + str(times) + "次尝试选择课程" + courseNo + ",但是没选到!")
(state, text) = postData(posturl, headers, data)
time.sleep(3) # sleep
return
def postRw(courseNo):
posturl = 'http://xk.urp.seu.edu.cn/jw_css/xk/runSelectclassSelectionAction.action?select_jxbbh=' + courseNo + '&select_xkkclx=45&select_jhkcdm=00034&select_mkbh=rwskl'
headers = {
'Host': 'xk.urp.seu.edu.cn',
'Proxy-Connection': 'keep-alive',
'Content-Length': '2',
'Accept': 'application/json, text/javascript, */*',
'Origin': 'http://xk.urp.seu.edu.cn',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
}
data = {
'{}': ''
}
(state, text) = postData(posturl, headers, data)
return (state, text)
def checkRwState(text):
if text.find('true') != -1: # 选课成功
return 0
if text.find('名额已满') != -1:
return 1
if text.find('冲突') != -1:
return 2
return -1
def Mode3(semesterNum, url):
(state, text) = selectSemester(semesterNum, url)
if state == False:
print(text.decode('utf-8'))
print('切换到学期' + str(semesterNum) + "失败")
return
else:
print('切换到学期' + str(semesterNum) + "成功")
print("==============\n模式3,开始选课\n==============")
# 获取人文课页面
geturl1 = 'http://xk.urp.seu.edu.cn/jw_css/xk/runViewsecondSelectClassAction.action?select_jhkcdm=00034&select_mkbh=rwskl&select_xkkclx=45&select_dxdbz=0'
header1 = {
'Host': 'xk.urp.seu.edu.cn',
'Proxy-Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
}
data1 = {}
(state, text) = getData(geturl1, header1, data1)
if state == False:
print("打开课程列表页面失败")
return
# 获取所有的课程编号
pattern = ('\"8%\" id=\"(.{0,20})\" align')
courseList = re.findall(pattern, text, re.S)
# print courseList
courseCtList = []
# 找出并去掉冲突的课程
for course in courseList:
(state, backText) = postRw(course)
if state == True: # ewww bad name here
state = checkRwState(backText)
else:
state = -1 # network error or something else
if state == 2:
courseCtList.append(course)
if state == 0:
print("Nice 选到了一门课:" + course)
return # 成功了
# print courseCtList
courseTemp = [i for i in courseList if (i not in courseCtList)]
# print courseTemp
times = 0
while True:
times = times + 1
# 找出已满的课程
pattern = ('已满.+?(\"8%\" id=\")(.{0,20})\" align')
courseYmList = [i[1] for i in re.findall(pattern, text, re.S)]
# print courseYmList
# 找出可以选的课程编号
courseAva = [i for i in courseTemp if (i not in courseYmList)]
# 选课了
if len(courseAva) == 0:
print("第" + str(times) + "次刷新,每门课都选不了..")
else:
for course in courseAva:
(state, text) = postRw(course)
if state == True:
state = checkRwState(text)
else:
state = -1
if state == 0:
print("Nice 选到了一门课:" + course)
return
if state == 1:
print("人品不好 眼皮子底下的课被抢了")
# 刷新人文选课界面
(state, text) = getData(geturl1, header1, data1)
if text.count('已选') == 3: # in case of multi-instances
print("已经选到一门课了")
break
if state == False:
print("打开课程列表页面失败")
return
time.sleep(3)
if __name__ == "__main__":
print("\n\n\n\n")
print("===================================================================== ")
print(" Seu_Jwc_Fker 东南大学选课助手\n")
print(" 访问 github.com/SnoozeZ/seu_jwc_fker 以了解本工具的最新动态")
print("===================================================================== ")
print("请选择模式:")
print("1. 同院竞争模式:只值守主界面本院的“服从推荐”课程(可选择指定的任意数量课程)")
print("2. 孤注一掷模式:只值守子界面“人文社科类”中你指定一门课程")
print("3. 暴力模式:值守子界面“人文社科类”任意一门课程,有剩余就选上")
# print u"4. 只值守子界面“自然科学与技术科学类”中的指定一门课程(开发中)"
# print u"5. 输入指定任意门课程的名字并值守(课程类型不限)(开发中)"
# mode = input(u'\n请输入模式编号(如:1):')
# userId = raw_input(u'请输入一卡通号(如:213111111):')
# passWord = raw_input(u'请输入密码(如:65535):')
# semester = input(u'请输入学期编号(短学期为1,秋季学期为2,春季学期为3):')
# inputCaptcha = raw_input(u"是否手动输入验证码? [y]/n: ")
# used for exporting to exe. damn you cmd
mode = eval(input('\n请输入模式编号(如:1):'))
semester = eval(input('请输入学期编号(短学期为1,秋季学期为2,春季学期为3):'))
inputCaptcha = input("是否手动输入验证码? [N]/Y: ")
if inputCaptcha == 'y' or inputCaptcha == 'Y': # should other cases be considered?
inputCaptcha = True
else:
inputCaptcha = False
ReadLocalDoc = input("是否读取本地账户信息? [y]/n: ")
userId = ""
passWord = ""
if ReadLocalDoc == 'n' or ReadLocalDoc == 'N': # should other cases be considered?
ReadLocalDoc = False
else:
ReadLocalDoc = True
if ReadLocalDoc == True:
if os.path.exists('Document.txt'):
with open('Document.txt', 'r') as LocalDoc:
lines = LocalDoc.readlines()
userId = lines[0]
userId = userId.strip('\n')
print('Local ID: ' + userId)
passWord = lines[1]
print('Local Password: ' + passWord)
else:
print("没有找到本地账户信息,请手动输入")
ReadLocalDoc = False
if not ReadLocalDoc:
userId = input('请输入一卡通号(如:213111111):')
passWord = input('请输入密码(如:65535):')
UpdateLocalDoc = input("是否更新本地账户信息? [y]/n: ")
if UpdateLocalDoc != 'n' and UpdateLocalDoc != 'N': # should other cases be considered?
with open('Document.txt', 'w') as LocalDoc:
LocalDoc.write(userId)
LocalDoc.write('\n')
LocalDoc.write(passWord)
ReadLocalLessonList = input("是否读取本地目标课程信息? [y]/n: ")
if ReadLocalLessonList == 'n' or ReadLocalLessonList == 'N': # should other cases be considered?
ReadLocalLessonList = False
else:
ReadLocalLessonList = True
if ReadLocalLessonList == True:
if os.path.exists('Lesson.txt'):
with open('Lesson.txt', 'r') as LocalLes:
WantedLessonsNameList = LocalLes.readlines()
for id, ls in enumerate(WantedLessonsNameList):
WantedLessonsNameList[id] = WantedLessonsNameList[id].strip('\n')
print(WantedLessonsNameList)
UpdateLocalLessonList = input("已找到本地课程信息,是否重新输入课程列表并更新? [n]/y:")
if UpdateLocalLessonList == 'y' or UpdateLocalLessonList == 'Y': # should other cases be considered?
while True:
WantedLes = input("请输入部分课程名称,输入0结束选择:")
if WantedLes != '0':
WantedLessonsNameList.append(WantedLes)
else:
break
print(WantedLessonsNameList)
with open('Lesson.txt', 'w') as LocalDoc:
for lessons in WantedLessonsNameList:
LocalDoc.write(lessons + '\n')
else:
UpdateLocalLessonList = input("没有找到本地课程信息,是否手动输入课程列表并自动更新?(选否待读取课程列表后手动选择) [y]/n:")
if UpdateLocalLessonList != 'n' and UpdateLocalLessonList != 'N': # should other cases be considered?
while True:
WantedLes = input("请输入部分课程名称,输入0结束选择:")
if WantedLes != '0':
WantedLessonsNameList.append(WantedLes)
else:
break
print(WantedLessonsNameList)
with open('Lesson.txt', 'w') as LocalDoc:
for lessons in WantedLessonsNameList:
LocalDoc.write(lessons + '\n')
state = False
failTimes = 0
while state == False:
(state, text, url) = loginIn(userId, passWord, inputCaptcha)
if state == True:
if 1 == mode:
Mode1(semester, url)
if 2 == mode:
courseName = input('请输入你想值守的人文课名称或者其关键词(如:音乐鉴赏):')
# courseName = raw_input(u'请输入你想值守的人文课名称或者其关键词(如:音乐鉴赏):') # used for exporting to exe
try:
courseName.decode('utf-8')
except:
courseName.decode('gbk').encode('utf-8') # handle the input from cmd
Mode2(semester, courseName, url)
if 3 == mode:
Mode3(semester, url)
else:
print("要不试试退出后重启一下本程序?")
eval(input('按任意键退出'))
# input(u'按任意键退出') #used for exporting to exe
def ContinueXuanKe():
Continue = input("是否继续选课? [y]/n: ")
if Continue == 'n' or Continue == 'N': # should other cases be considered?
eval(input('按任意键退出'))
quit()
print("\n===================================================================== ")
print(" Seu_Jwc_Fker 东南大学选课助手\n")
print(" 访问 github.com/SnoozeZ/seu_jwc_fker 以了解本工具的最新动态")
print("===================================================================== ")
print("请选择模式:")
print("1. 同院竞争模式:只值守主界面本院的“服从推荐”课程(可选择指定的任意数量课程)")
print("2. 孤注一掷模式:只值守子界面“人文社科类”中你指定一门课程")
print("3. 暴力模式:值守子界面“人文社科类”任意一门课程,有剩余就选上")
mode = eval(input('\n请输入模式编号(如:1):'))
if state == True:
if 1 == mode:
Mode1(semester, url)
if 2 == mode:
courseName = input('请输入你想值守的人文课名称或者其关键词(如:音乐鉴赏):')
# courseName = raw_input(u'请输入你想值守的人文课名称或者其关键词(如:音乐鉴赏):') # used for exporting to exe
try:
courseName.decode('utf-8')
except:
courseName.decode('gbk').encode('utf-8') # handle the input from cmd
Mode2(semester, courseName, url)
if 3 == mode:
Mode3(semester, url)