奕辅导自动打卡脚本
打卡脚本,使用前需手动打卡一次并需要抓包,在其中找到相关的token。
# -*- encoding:utf-8 -*- import requests import json punch_in_data = { "questionnairePublishEntityId": "1001640744275339000980000000001", "answerInfoList": [ { "subjectId": "1001640315554537000980000000001", "subjectType": "multiSelect", "multiSelect": { "optionAnswerList": [ { "beSelectValue": "NotThing", "fillContent": "" } ] } }, { "subjectId": "1001640672356535001000000000001", "subjectType": "location", "location": { 'address':'**市**区***', 'area':'**区', 'city':'**市', 'deviationDistance':'1******', 'latitude':'', 'locationRangeId':'', 'longitude':'', 'province':'**省', 'street':'**' } }, { "subjectId": "1001647490263982000200000000001", "subjectType": "multiSelect", "optionAnswerList": { 'attachmentList':'(null)', 'beSelectValue':'1', "fillContent": "" } }, { "subjectId": "1001647684101571001820000000001", "subjectType": "multiSelect", "optionAnswerList": { "beSelectValue": "1", "fillContent": "" } }, ] } class YiFuDao_Puncher: def __init__(self): self.base_url = "https://yfd.ly-sky.com" self.header = { "accessToken": '',#填入抓取的token "userAuthType": "MS" } self.puncher_status = "💚 打卡脚本初始化中" self.check_in_index() def check_in_index(self): try: url = "/ly-pd-mb/form/api/healthCheckIn/client/stu/index" id=None retry=3 while id is None and retry>=0: retry-=1 res = requests.get(self.base_url+url, headers=self.header) parse_data = json.loads(res.text) detail = dict.get(parse_data,"data") id = dict.get(detail,"questionnairePublishEntityId") # 表单ID,每日不同 filling_status = dict.get(detail, "hadFill") # 填写状态 start_time = dict.get(detail, "fillStartTime") # 获取问卷开始时间 if start_time: break print("💚 打卡脚本初始化完成") self.puncher_status = "✔ 已获取健康打卡信息" if id is None: if start_time is not None: self.puncher_status = "❗ 还未到打卡时间,脚本自动结束" print("❗ 还未到打卡时间,脚本自动结束") else: self.puncher_status = "❌ 获取问卷失败,请稍后重试" print("❌ 获取问卷失败,请稍后重试") return 0 if filling_status is False: self.puncher_status = "✔ 今天暂未打卡,尝试进行打卡" self.check_in_detail(str(id)) else: self.puncher_status = "❗ 今天已经打卡,脚本自动结束" print("❗ 今天已经打卡,脚本自动结束") return 0 except Exception as e: self.puncher_status = "❌ 获取健康打卡信息失败" print("❌ 获取健康打卡信息失败") def check_in_detail(self,id): try: url = "/ly-pd-mb/form/api/questionnairePublish/" + str(id) + "/getDetailWithAnswer" res = requests.get(self.base_url+url,headers=self.header) parse_data = json.loads(res.text) subjectList = dict.get(dict.get(dict.get(parse_data,"data"),"questionnaireWithSubjectVo"),"subjectList") question_id_list = [] answer_id_list = [] for i in subjectList: question_id_list.append(i["id"]) for i in punch_in_data["answerInfoList"]: answer_id_list.append(i["subjectId"]) # 判断预设答案与当前问卷的项是否相符 if answer_id_list == question_id_list: punch_in_data["questionnairePublishEntityId"] = str(id) self.puncher_status = "✔ 预设答案与当前问卷的项相符,本次打卡的问卷id为{}".format(punch_in_data["questionnairePublishEntityId"]) print("✔ 预设答案与当前问卷的项相符,本次打卡的问卷id为{}".format(punch_in_data["questionnairePublishEntityId"])) self.check_in_save() else: self.puncher_status = "❌ 预设答案与当前问卷的项不相符,脚本已结束" print("❌ 预设答案与当前问卷的项不相符,脚本已结束") return 0 except Exception as e: print("❌ 获取问卷详情失败") def check_in_save(self): try: url = "/ly-pd-mb/form/api/answerSheet/saveNormal" header = self.header header["Content-Type"] = "application/json" res = requests.post(self.base_url+url,data=json.dumps(punch_in_data),headers=header) parse_data = json.loads(res.text) if parse_data["code"] == 200: self.puncher_status = "✔ 打卡成功,{}".format(parse_data["message"]) print("✔ 打卡成功,{}".format(parse_data["message"])) else: self.puncher_status = "❌ 打卡失败,{}".format(parse_data["message"]) except Exception as e: print("❌ 打卡失败") if __name__=="__main__": YiFuDao_Puncher().check_in_save()
自动打卡的实现则需要去部署腾讯云函数(其它厂商的也行),在云函数中设置执行周期。相关的实现教程请前往云函数部署教程。
还没有评论,来说两句吧...