-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
107 lines (88 loc) · 3.2 KB
/
main.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
import time
import requests
# 刷课速度,默认两倍速,想秒过的可以改成一个极大的数字
speed = 2
loginUrl = r'http://service.zjooc.cn/service/centro/api/auth/app/authorize'
coursesUrl = r'http://service.zjooc.cn/service/jxxt/api/app/course/student/course?publishStatus=3&pageNo=1&pageSize=10'
chapterUrl = r'http://service.zjooc.cn/service/jxxt/api/app/course/chapter/getStudentCourseChapters'
videoUrl = r'http://service.zjooc.cn/service/learningmonitor/api/learning/monitor/videoPlaying'
textUrl = r'http://service.zjooc.cn/service/learningmonitor/api/learning/monitor/finishTextChapter'
headers = {}
print("账号(通常为手机号):")
account = input()
print("密码:")
passwd = input()
courseId = ''
def finish_video(chapter):
length = chapter['vedioTimeLength']
chapter_id = chapter['id']
for i in range(int(length / (10 * speed))):
r = requests.get(videoUrl, params={
'chapterId': chapter_id,
'playTime': i * 20,
'percent': int(i * (10 * speed) / length * 100),
'quitFlag': 0,
'thisWatchTime': 0,
'courseId': courseId
}, headers=headers)
if r.status_code != 200 or r.json()['success'] is False:
raise Exception(r.json()['message'])
print('%d%%' % int(i * (10 * speed) / length * 100))
time.sleep(10)
r = requests.get(videoUrl, params={
'chapterId': chapter_id,
'playTime': length,
'percent': 100,
'quitFlag': 1,
'thisWatchTime': length,
'courseId': courseId
}, headers=headers)
if r.status_code != 200 or r.json()['success'] is False:
raise Exception(r.json()['message'])
def finish_text(chapter):
chapter_id = chapter['id']
r = requests.get(textUrl, params={
'courseId': courseId,
'chapterId': chapter_id
}, headers=headers)
if r.status_code != 200 or r.json()['success'] is False:
raise Exception(r.json()['message'])
resp = requests.post(loginUrl, json={"login_name": account, "password": passwd, "type": 1})
if resp.status_code != 200 or resp.json()['success'] is False:
print('登陆失败:', resp.json()['message'])
exit(0)
headers['openid'] = resp.json()['data']['loginResult']['openid']
print("课程")
resp = requests.get(coursesUrl, headers=headers)
courses = resp.json()['data']
i = 0
for course in courses:
print('[%d]%s' % (i, course['courseName']))
i += 1
index = input("输入要刷的课程序号:")
courseId = courses[int(index)]['id']
resp = requests.get(chapterUrl, params={
'courseId': courseId,
'source': 1,
'urlNeed': 1
}, headers=headers)
chapterList = []
for v in resp.json()['data']:
for u in v['children']:
chapterList.extend(u['children'])
for chapter in chapterList:
print("开始学习%s" % chapter['name'])
if chapter['learnStatus'] == 2:
print("已学习,跳过")
continue
if chapter['resourceType'] == 1:
try:
finish_video(chapter)
except Exception as err:
print(err)
elif chapter['resourceType'] == 3:
try:
finish_text(chapter)
except Exception as err:
print(err)
print("学习完成")