1515from Crypto .Cipher import AES
1616from Crypto .Hash import MD5
1717from Crypto .Util .Padding import pad
18+ from ZJYMain .audio_utils import calculate_audio_study_params
1819
1920logging .basicConfig (level = logging .INFO , format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
2021logger = logging .getLogger (__name__ )
@@ -160,7 +161,7 @@ def study_record(session, info, class_id):
160161 file_type = info ['fileType' ]
161162 course_id = info .get ('id' ) or info .get ('activityId' )
162163 course_info_id = info ['courseInfoId' ]
163- file_url = json .loads (info ['fileUrl' ])['url' ]
164+ file_url = json .loads (info ['fileUrl' ])['url' ] if info . get ( 'fileUrl' ) else ''
164165 if file_type in ["img" , "图文" ]:
165166 resp_result = stu_process_cell_log (session , course_info_id , class_id , random .randint (12 , 22 ), course_id , 1 )
166167 sleep_randint = random .randint (5 , 10 )
@@ -173,14 +174,15 @@ def study_record(session, info, class_id):
173174 sleep_randint = random .randint (5 , 10 )
174175 logging .info ('\t \t \t \t \t \t 学习课件中... 课程: %s 延时: %s 结果: %s' , name , sleep_randint , resp_result )
175176 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)
177+ elif file_type == "audio" :
178+ audio_params = calculate_audio_study_params (info )
179+ study_time = audio_params ['study_time' ]
180+ duration_seconds = audio_params ['duration_seconds' ]
181+ resp_result = stu_process_cell_log (session , course_info_id , class_id , study_time , course_id , duration_seconds )
182+ logging .info ('\t \t \t \t \t \t 学习课件中... 课程: %s 学习时长: %s秒 延时: %s 结果: %s' , name , duration_seconds , sleep_randint , resp_result )
183+ time .sleep (sleep_randint )
182184 elif file_type == "video" :
183- video_time = get_video_time (session , file_url )['args' ][ 'duration' ]
185+ video_time = get_video_time (session , file_url )['args' ]. get ( 'duration' , '00:10' )
184186 total_seconds = int (sum (float (x ) * 60 ** i for i , x in enumerate (reversed (video_time .split (':' )))))
185187 study_time = total_seconds + random .randint (12 , 22 )
186188 resp_result = stu_process_cell_log (session , course_info_id , class_id , study_time , course_id , total_seconds )
@@ -197,12 +199,12 @@ def process_standard_course(session, i):
197199 moduleList1 = get_process_list (session , i ['courseId' ], i ['courseInfoId' ], i ['classId' ], 0 , 1 )
198200
199201 for j in moduleList1 :
200- time .sleep (random .uniform (0.5 , 1 ))
201202 if j ['speed' ] == 100 :
202203 logging .info ("\t %s 课程已刷进度 100" , j ['name' ])
203204 continue
204205 logging .info ("\t %s" , j ['name' ])
205206 # 二级目录
207+ time .sleep (random .uniform (0.5 , 1 ))
206208 moduleList2 = get_process_list (session , i ['courseId' ], i ['courseInfoId' ], i ['classId' ], j ['id' ], 2 )
207209 for k in moduleList2 :
208210 # time.sleep(random.uniform(0.5, 1))
0 commit comments