Skip to content

Commit cffa4e8

Browse files
committed
[FEAT] 适配-快速课程
1 parent 88b1eca commit cffa4e8

File tree

1 file changed

+150
-58
lines changed

1 file changed

+150
-58
lines changed

ZJYMain/look_video.py

Lines changed: 150 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
import random
1111
import time
12+
from datetime import timedelta, datetime
1213
from urllib.parse import quote
1314

1415
from Crypto.Cipher import AES
@@ -27,18 +28,25 @@
2728
# 获取学习课程列表
2829
GET_LEARNNING_COURSE_LIST = BASE_URL + '/spoc/courseInfoStudent/myCourseList'
2930

31+
# 获取内容资源列表 fast
32+
GET_STUDENT_TEACH_DATE_FAST = BASE_URL + '/spoc/courseFaceTeachActivity/getStudentTeachDate'
33+
3034
# 获取一级目录
3135
GET_PROCESS_LIST = BASE_URL + '/spoc/courseDesign/study/record'
36+
GET_PROCESS_LIST_FAST = BASE_URL + '/spoc/courseFaceTeachInfo/fast/student/info'
3237

3338
# 刷课记录时长
3439
STU_PROCESS_CELL_LOG = BASE_URL + '/spoc/studyRecord/update'
40+
STU_PROCESS_CELL_LOG_FAST = BASE_URL + '/spoc/fast/course/study'
3541

3642
# PPT类型获取总页数
3743
GET_URL_PNGS = BASE_URL + '/spoc/oss/getUrlPngs'
3844

3945
# 视频获取时长
4046
GET_VIDEO_TIME = 'https://upload.icve.com.cn/{}/status'
4147

48+
is_fast = False
49+
4250

4351
# 1.获取所有课程
4452
def get_learnning_course_list(session):
@@ -50,17 +58,51 @@ def get_learnning_course_list(session):
5058
return result.json()
5159

5260

53-
# 2.得到一级目录
54-
def get_process_list(session, course_id, course_info_id, open_class_id, parent_id, level):
61+
# 2.得到资源列表 fast
62+
def get_process_list_fast(session, course_id, course_info_id, open_class_id):
63+
# 获取结束时间(今天+1天)
64+
end_date = datetime.now() + timedelta(days=1)
65+
# 获取开始时间(结束时间-365天)
66+
start_date = end_date - timedelta(days=365)
5567
data = {
56-
'courseId': course_id,
57-
'courseInfoId': course_info_id,
58-
'parentId': parent_id,
59-
"level": level,
60-
"classId": open_class_id
68+
"courseId": course_id,
69+
"courseInfoId": course_info_id,
70+
"classId": open_class_id,
71+
"startDate": start_date.strftime("%Y-%m-%d"),
72+
"endDate": end_date.strftime("%Y-%m-%d"),
73+
"pageNum": 1,
74+
"pageSize": 1000,
75+
"teachType": 1
6176
}
6277

63-
result = session.get(url=GET_PROCESS_LIST, params=data, headers=headers)
78+
result = session.get(url=GET_STUDENT_TEACH_DATE_FAST, params=data, headers=headers)
79+
return result.json()
80+
81+
82+
# 2.得到一级目录
83+
def get_process_list(session, course_id, course_info_id, open_class_id, parent_id, level, start_date=''):
84+
if is_fast:
85+
data = {
86+
"courseId": course_id,
87+
"courseInfoId": course_info_id,
88+
"classId": open_class_id,
89+
"teachType": "1",
90+
"startDate": start_date,
91+
"EndDate": start_date,
92+
"requireType": "2"
93+
}
94+
95+
result = session.get(url=GET_PROCESS_LIST_FAST, params=data, headers=headers)
96+
else:
97+
data = {
98+
'courseId': course_id,
99+
'courseInfoId': course_info_id,
100+
'parentId': parent_id,
101+
"level": level,
102+
"classId": open_class_id
103+
}
104+
105+
result = session.get(url=GET_PROCESS_LIST, params=data, headers=headers)
64106
return result.json()
65107

66108

@@ -75,6 +117,8 @@ def stu_process_cell_log(session, course_info_id, class_id, study_time, source_i
75117
"actualNum": total_num,
76118
"lastNum": total_num,
77119
}
120+
if is_fast:
121+
data['type'] = 1
78122

79123
def encrypt_data(_data):
80124
access_token = session.access_token
@@ -86,7 +130,10 @@ def encrypt_data(_data):
86130
return base64.b64encode(encrypted_data).decode()
87131

88132
param = {"param": quote(encrypt_data(data))}
89-
result = session.post(url=STU_PROCESS_CELL_LOG, json=param, headers=headers)
133+
if is_fast:
134+
result = session.post(url=STU_PROCESS_CELL_LOG_FAST, json=param, headers=headers)
135+
else:
136+
result = session.post(url=STU_PROCESS_CELL_LOG, json=param, headers=headers)
90137
try:
91138
return result.json()['msg']
92139
except Exception as e:
@@ -109,9 +156,9 @@ def get_video_time(session, file_url):
109156
def study_record(session, info, class_id):
110157
sleep_randint = random.randint(5, 10)
111158
time.sleep(sleep_randint)
112-
name = info['name']
159+
name = info.get('name') or info.get('title')
113160
file_type = info['fileType']
114-
course_id = info['id']
161+
course_id = info.get('id') or info.get('activityId')
115162
course_info_id = info['courseInfoId']
116163
file_url = json.loads(info['fileUrl'])['url']
117164
if file_type in ["img", "图文"]:
@@ -126,6 +173,12 @@ def study_record(session, info, class_id):
126173
sleep_randint = random.randint(5, 10)
127174
logging.info('\t\t\t\t\t\t学习课件中... 课程: %s 延时: %s 结果: %s', name, sleep_randint, resp_result)
128175
time.sleep(sleep_randint)
176+
# elif file_type == "audio":
177+
# audio_time = content_audio(session, course_id, course_id)
178+
# audio_time_sec = time_to_seconds(audio_time)
179+
# resp_result = stu_process_cell_log(session, course_info_id, class_id, audio_time_sec, course_id, audio_time)
180+
# logging.info('\t\t\t\t\t\t学习课件中... 课程: %s 延时: %s 结果: %s', name, sleep_randint, resp_result)
181+
# time.sleep(sleep_randint)
129182
elif file_type == "video":
130183
video_time = get_video_time(session, file_url)['args']['duration']
131184
total_seconds = int(sum(float(x) * 60 ** i for i, x in enumerate(reversed(video_time.split(':')))))
@@ -138,7 +191,85 @@ def study_record(session, info, class_id):
138191
logging.info("\t\t\t\t\t\t文件类型不支持请提交反馈进行适配: %s, 课程: %s", file_type, name)
139192

140193

194+
def process_standard_course(session, i):
195+
"""处理标准课程"""
196+
# 一级目录
197+
moduleList1 = get_process_list(session, i['courseId'], i['courseInfoId'], i['classId'], 0, 1)
198+
199+
for j in moduleList1:
200+
time.sleep(random.uniform(0.5, 1))
201+
if j['speed'] == 100:
202+
logging.info("\t%s 课程已刷进度 100", j['name'])
203+
continue
204+
logging.info("\t%s", j['name'])
205+
# 二级目录
206+
moduleList2 = get_process_list(session, i['courseId'], i['courseInfoId'], i['classId'], j['id'], 2)
207+
for k in moduleList2:
208+
# time.sleep(random.uniform(0.5, 1))
209+
logging.info("\t\t%s", k['name'])
210+
# 三级目录
211+
moduleList3 = get_process_list(session, i['courseId'], i['courseInfoId'], i['classId'], k['id'], 3)
212+
for m in moduleList3:
213+
# time.sleep(random.uniform(0.5, 1))
214+
if m['speed'] == 100:
215+
logging.info("\t\t\t%s 课程已刷进度 100", m['name'])
216+
continue
217+
logging.info("\t\t\t\t%s", m['name'])
218+
# 如果只有三级目录
219+
if not m.get('children') or not len(m.get('children', [])):
220+
# 如果课程完成-不刷课
221+
if m['speed'] == 100:
222+
logging.info("\t\t\t\t\t%s 课程已刷进度 100%", m['name'])
223+
continue
224+
# 将信息拿去刷课
225+
try:
226+
study_record(session, m, i['classId'])
227+
except Exception as e:
228+
logging.error("错误跳过: %s", e)
229+
# 四级目录(最终)
230+
else:
231+
for n in m.get('children', []):
232+
# time.sleep(random.uniform(1, 1.5))
233+
# 如果课程完成-不刷课
234+
if n['speed'] == 100:
235+
logging.info("\t\t\t\t\t%s 课程已刷进度 100", n['name'])
236+
continue
237+
# 将信息拿去刷课
238+
239+
try:
240+
study_record(session, n, i['classId'])
241+
except Exception as e:
242+
logging.error("错误跳过: %s", e)
243+
244+
245+
def process_fast_course(session, i):
246+
"""处理快速课程"""
247+
moduleList1 = get_process_list_fast(session, i['courseId'], i['courseInfoId'], i['classId'])
248+
for k in moduleList1.get('rows', []):
249+
# time.sleep(random.uniform(0.5, 1))
250+
logging.info("\t\t%s %s 活动: %s", k['dateStr'], k['name'], k['num'])
251+
# 进入级目录
252+
moduleList2 = get_process_list(session, i['courseId'], i['courseInfoId'], i['classId'], k.get('id'), 3,
253+
k['dateStr'])
254+
for m in moduleList2.get('data', []):
255+
# time.sleep(random.uniform(0.5, 1))
256+
if m['speed'] == 100:
257+
logging.info("\t\t\t%s 课程已刷进度 100", m['title'])
258+
continue
259+
logging.info("\t\t\t\t%s", m['title'])
260+
# 如果课程完成-不刷课
261+
if m['speed'] == 100:
262+
logging.info("\t\t\t\t\t%s 课程已刷进度 100%", m['title'])
263+
continue
264+
# 将信息拿去刷课
265+
try:
266+
study_record(session, m, i['classId'])
267+
except Exception as e:
268+
logging.error("错误跳过: %s", e)
269+
270+
141271
def start(session, jump_content):
272+
global is_fast
142273
separator = "*" * 40
143274
logger.info(separator)
144275
logger.info(f"运行信息")
@@ -169,50 +300,11 @@ def start(session, jump_content):
169300
logger.info("\t匹配到过滤条件: %s - 跳过", i['courseName'])
170301
continue
171302
time.sleep(random.uniform(1, 1.5))
172-
# 一级目录
173-
moduleList1 = get_process_list(session, i['courseId'], i['courseInfoId'], i['classId'], 0, 1)
174-
175-
for j in moduleList1:
176-
time.sleep(random.uniform(0.5, 1))
177-
if j['speed'] == 100:
178-
logging.info("\t%s 课程已刷进度 100", j['name'])
179-
continue
180-
logging.info("\t%s", j['name'])
181-
# 二级目录
182-
moduleList2 = get_process_list(session, i['courseId'], i['courseInfoId'], i['classId'], j['id'], 2)
183-
for k in moduleList2:
184-
# time.sleep(random.uniform(0.5, 1))
185-
logging.info("\t\t%s", k['name'])
186-
# 三级目录
187-
moduleList3 = get_process_list(session, i['courseId'], i['courseInfoId'], i['classId'], k['id'], 3)
188-
for m in moduleList3:
189-
# time.sleep(random.uniform(0.5, 1))
190-
if m['speed'] == 100:
191-
logging.info("\t\t\t%s 课程已刷进度 100", m['name'])
192-
continue
193-
logging.info("\t\t\t\t%s", m['name'])
194-
# 如果只有三级目录
195-
if not m.get('children') or not len(m.get('children', [])):
196-
# 如果课程完成-不刷课
197-
if m['speed'] == 100:
198-
logging.info("\t\t\t\t\t%s 课程已刷进度 100%", m['name'])
199-
continue
200-
# 将信息拿去刷课
201-
try:
202-
study_record(session, m, i['classId'])
203-
except Exception as e:
204-
logging.error("错误跳过: %s", e)
205-
# 四级目录(最终)
206-
else:
207-
for n in m.get('children', []):
208-
# time.sleep(random.uniform(1, 1.5))
209-
# 如果课程完成-不刷课
210-
if n['speed'] == 100:
211-
logging.info("\t\t\t\t\t%s 课程已刷进度 100", n['name'])
212-
continue
213-
# 将信息拿去刷课
214-
215-
try:
216-
study_record(session, n, i['classId'])
217-
except Exception as e:
218-
logging.error("错误跳过: %s", e)
303+
if i['isCriteria'] == 0:
304+
# 快速课程
305+
is_fast = True
306+
process_fast_course(session, i)
307+
else:
308+
# 标准课程
309+
is_fast = False
310+
process_standard_course(session, i)

0 commit comments

Comments
 (0)