forked from whitebear354/AutoWeiBan
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
103 lines (89 loc) · 4.13 KB
/
main.py
File metadata and controls
103 lines (89 loc) · 4.13 KB
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
import WeiBanAPI
import json
import time # time.sleep延时
import os # 兼容文件系统
import random
tenantCode = '61050002' # 成电ID
def main():
# 显示License
licenseFile = open('.' + os.sep + 'LICENSE', encoding='utf-8')
print(licenseFile.read())
licenseFile.close()
# 登录
# 补打空cookie
cookie = ''
loginResponse = WeiBanAPI.qrLogin()
try:
print('登录成功,userName:' + loginResponse['data']['userName'])
time.sleep(2)
except BaseException:
print('登录失败')
print(loginResponse) # TODO: 这里的loginResponse调用没有考虑网络错误等问题
exit(0)
# 请求解析并打印用户信息
try:
print('请求用户信息')
stuInfoResponse = WeiBanAPI.getStuInfo(loginResponse['data']['userId'],
tenantCode,
cookie)
print('用户信息:' + stuInfoResponse['data']['realName'] + '\n'
+ stuInfoResponse['data']['orgName']
+ stuInfoResponse['data']['specialtyName']
)
time.sleep(2)
except BaseException:
print('解析用户信息失败,将尝试继续运行,请注意运行异常')
# 请求课程完成进度
try:
getProgressResponse = WeiBanAPI.getProgress(loginResponse['data']['preUserProjectId'],
tenantCode,
cookie)
print('课程总数:' + str(getProgressResponse['data']['requiredNum']) + '\n'
+ '完成课程:' +
str(getProgressResponse['data']['requiredFinishedNum']) + '\n'
+ '结束时间' + str(getProgressResponse['data']['endTime']) + '\n'
+ '剩余天数' + str(getProgressResponse['data']['lastDays'])
)
time.sleep(2)
except BaseException:
print('解析课程进度失败,将尝试继续运行,请注意运行异常')
# 请求课程列表
try:
getListCategoryResponse = WeiBanAPI.getListCategory(loginResponse['data']['preUserProjectId'],
'3',
tenantCode,
loginResponse['data']['userId'],
loginResponse['data']['token'])
time.sleep(2)
except BaseException:
print('请求课程列表失败')
print('解析课程列表并发送完成请求')
for Category in getListCategoryResponse['data']:
print('\n----章节码:' + Category['categoryCode'] +
'章节内容:' + Category['categoryName'])
try:
getListCourseResponse = WeiBanAPI.getListCourse(loginResponse['data']['preUserProjectId'],
'3',
Category['categoryCode'],
'',
loginResponse['data']['userId'],
tenantCode,
loginResponse['data']['token'])
time.sleep(2)
except BaseException:
print('请求课程列表失败')
for j in getListCourseResponse['data']:
print('课程内容:' + j['resourceName'] +
'\nuserCourseId:' + j['userCourseId'])
if (j['finished'] == 1):
print('已完成')
else:
print('发送完成请求')
WeiBanAPI.doStudy(
loginResponse['data']['preUserProjectId'], j['resourceId'], tenantCode)
WeiBanAPI.finishCourse(j['userCourseId'], tenantCode, cookie)
delayInt = WeiBanAPI.getRandomTime()
print('\n随机延时' + str(delayInt))
time.sleep(delayInt)
if __name__ == '__main__':
main()