-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.py
More file actions
100 lines (84 loc) · 3.59 KB
/
main.py
File metadata and controls
100 lines (84 loc) · 3.59 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
import WeiBanAPI
import json
import time # time.sleep延时
import os # 兼容文件系统
import random
tenantCode = '51900002' # 吉珠院校ID
# License
licenseFile = open('.' + os.sep + 'LICENSE', encoding='utf-8')
print(licenseFile.read())
licenseFile.close()
print(
'默认院校为吉林大学珠海学院,ID:' + tenantCode + '\n'
+ '若有需要,请自行抓包获取院校ID修改' + '\n'
)
# 登录信息输入
account = input('请输入账号\n')
password = input('请输入密码\n')
# 获取Cookies
print('\n获取Cookies中')
cookie = WeiBanAPI.getCookie()
print('Cookies获取成功')
time.sleep(2)
randomTimeStamp = random.randint(100000000, 1000000000000)
print('验证码,浏览器打开 https://weiban.mycourse.cn/pharos/login/randImage.do?time=' + str(randomTimeStamp))
verifyCode = input('请输入验证码')
# 登录请求
loginResponse = WeiBanAPI.login(account, password, tenantCode, randomTimeStamp, verifyCode, cookie)
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']['courseNum']) + '\n'
+ '完成课程:' + str(getProgressResponse['data']['courseFinishedNum']) + '\n'
+ '结束时间' + str(getProgressResponse['data']['endTime']) + '\n'
+ '剩余天数' + str(getProgressResponse['data']['lastDays'])
)
time.sleep(2)
except BaseException:
print('解析课程进度失败,将尝试继续运行,请注意运行异常')
# 请求课程列表
try:
getListCourseResponse = WeiBanAPI.getListCourse(loginResponse['data']['preUserProjectId'],
'3',
tenantCode,
'',
cookie)
time.sleep(2)
except BaseException:
print('请求课程列表失败')
print('解析课程列表并发送完成请求')
for i in getListCourseResponse['data']:
print('\n----章节码:' + i['categoryCode'] + '章节内容:' + i['categoryName'])
for j in i['courseList']:
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)