[\s]+
(.*)'
134 | r = self.session.get(
135 | 'https://mobilelearn.chaoxing.com/widget/pcpick/stu/index?courseId={}&jclassId={}'.format(
136 | courseid, classid), headers=self.headers, verify=False)
137 | res = re.findall(re_rule, r.text)
138 | # sign_type = re.findall(sign_type_re_rule, r.text)
139 | # print(sign_type)
140 | if res != []: # 满足签到条件
141 | return {
142 | 'classid': classid,
143 | 'courseid': courseid,
144 | 'activeid': res[0][0],
145 | 'classname': classname,
146 | 'sign_type': res[0][1]
147 | }
148 |
149 | def general_sign(self, classid, courseid, activeid):
150 | """普通签到"""
151 | r = self.session.get(
152 | 'https://mobilelearn.chaoxing.com/widget/sign/pcStuSignController/preSign?activeId={}&classId={}&fid=39037&courseId={}'.format(
153 | activeid, classid, courseid), headers=self.headers, verify=False)
154 | title = re.findall('
(.*)', r.text)[0]
155 | if "签到成功" not in title:
156 | # 网页标题不含签到成功,则为拍照签到
157 | return self.tphoto_sign(activeid)
158 | else:
159 | sign_date = re.findall('
(.*)', r.text)[0]
160 | s = {
161 | 'date': sign_date,
162 | 'status': title
163 | }
164 | return s
165 |
166 | def hand_sign(self, classid, courseid, activeid):
167 | """手势签到"""
168 | hand_sign_url = "https://mobilelearn.chaoxing.com/widget/sign/pcStuSignController/signIn?&courseId={}&classId={}&activeId={}".format(
169 | courseid, classid, activeid)
170 | r = self.session.get(hand_sign_url, headers=self.headers, verify=False)
171 | title = re.findall('
(.*)', r.text)
172 | sign_date = re.findall('
(.*)', r.text)[0]
173 | s = {
174 | 'date': sign_date,
175 | 'status': title
176 | }
177 | return s
178 |
179 | def qcode_sign(self, activeId):
180 | """二维码签到"""
181 | params = {
182 | 'name': '',
183 | 'activeId': activeId,
184 | 'uid': '',
185 | 'clientip': '',
186 | 'useragent': '',
187 | 'latitude': '-1',
188 | 'longitude': '-1',
189 | 'fid': '',
190 | 'appType': '15'
191 | }
192 | res = self.session.get('https://mobilelearn.chaoxing.com/pptSign/stuSignajax', params=params)
193 | s = {
194 | 'date': time.strftime("%m-%d %H:%M", time.localtime()) ,
195 | 'status': res.text
196 | }
197 | return s
198 |
199 | def addr_sign(self, activeId):
200 | """位置签到"""
201 | params = {
202 | 'name': '',
203 | 'activeId': activeId,
204 | 'address': '中国',
205 | 'uid': '',
206 | 'clientip': '0.0.0.0',
207 | 'latitude': '-2',
208 | 'longitude': '-1',
209 | 'fid': '',
210 | 'appType': '15',
211 | 'ifTiJiao': '1'
212 | }
213 | res = self.session.get('https://mobilelearn.chaoxing.com/pptSign/stuSignajax', params=params)
214 | s = {
215 | 'date': time.strftime("%m-%d %H:%M", time.localtime()),
216 | 'status': res.text
217 | }
218 | return s
219 |
220 | def tphoto_sign(self, activeId):
221 | """拍照签到"""
222 | params = {
223 | 'name': '',
224 | 'activeId': activeId,
225 | 'address': '中国',
226 | 'uid': '',
227 | 'clientip': '0.0.0.0',
228 | 'latitude': '-2',
229 | 'longitude': '-1',
230 | 'fid': '',
231 | 'appType': '15',
232 | 'ifTiJiao': '1',
233 | 'objectId': '5712278eff455f9bcd76a85cd95c5de3'
234 | }
235 | res = self.session.get('https://mobilelearn.chaoxing.com/pptSign/stuSignajax', params=params)
236 | print(res.text)
237 | s = {
238 | 'date': time.strftime("%m-%d %H:%M", time.localtime()),
239 | 'status': res.text
240 | }
241 | return s
242 |
243 | def sign_in(self, classid, courseid, activeid, sign_type):
244 | """签到类型的逻辑判断"""
245 | if self.check_activeid(activeid):
246 | return
247 | if "手势" in sign_type:
248 | # test:('拍照签到', 'success')
249 | return self.hand_sign(classid, courseid, activeid)
250 |
251 | elif "二维码" in sign_type:
252 | return self.qcode_sign(activeid)
253 |
254 | elif "位置" in sign_type:
255 | return self.addr_sign(activeid)
256 |
257 | else:
258 | # '[2020-03-20 14:42:35]-[签到成功]'
259 | r = self.general_sign(classid, courseid, activeid)
260 | return r
261 |
262 | def sign_tasks_run(self):
263 | """开始所有签到任务"""
264 | tasks = []
265 | sign_msg = {}
266 | final_msg = []
267 | # 获取所有课程的classid和course_id
268 | classid_courseId = self.get_all_classid()
269 |
270 | # 获取所有课程activeid和签到类型
271 | for i in classid_courseId:
272 | coroutine = self.get_activeid(i[1], i[0], i[2])
273 | tasks.append(coroutine)
274 |
275 | loop = asyncio.new_event_loop()
276 | asyncio.set_event_loop(loop)
277 | result = loop.run_until_complete(asyncio.gather(*tasks))
278 |
279 | for d in result:
280 | if d is not None:
281 | s = self.sign_in(d['classid'], d['courseid'], d['activeid'], d['sign_type'])
282 | if not s:
283 | return
284 | # 签到课程, 签到时间, 签到状态
285 | sign_msg = {
286 | 'name': d['classname'],
287 | 'date': s['date'],
288 | 'status': s['status']
289 | }
290 | final_msg.append(sign_msg)
291 | return final_msg
292 |
293 |
294 | def server_chan_send(msg):
295 | """server酱将消息推送至微信"""
296 | desp = ''
297 | for d in msg:
298 | desp = '| **课程名** | {} |\r| :----------: | :---------- |\r'.format(d['name'])
299 | desp += '| **签到时间** | {} |\r'.format(d['date'])
300 | desp += '| **签到状态** | {} |\r'.format(d['status'])
301 |
302 | params = {
303 | 'text': '您的网课签到消息来啦!!',
304 | 'desp': desp
305 | }
306 |
307 | requests.get(server_chan['url'], params=params)
308 |
309 |
310 | def local_run():
311 | # 本地运行使用
312 | if "activeid.txt" not in os.listdir("./"):
313 | with open(activeid_path, 'w+') as f:
314 | f.write("")
315 | s = AutoSign(user_info['username'], user_info['password'])
316 | result = s.sign_tasks_run()
317 | if result:
318 | if server_chan['status']:
319 | server_chan_send(result)
320 | return result
321 | else:
322 | return "暂无签到任务"
323 |
324 |
325 | if __name__ == '__main__':
326 | print(local_run())
327 |
--------------------------------------------------------------------------------