奕輔導自動打卡腳本
打卡腳本,使用前需手動打卡一次并需要抓包,在其中找到相關的token。
# -*- encoding:utf-8 -*-import requests
import jsonpunch_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=Noneretry=3while id is None and retry>=0:retry-=1res = 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:breakprint("💚 打卡腳本初始化完成")self.puncher_status = "? 已獲取健康打卡信息"if id is None:if start_time is not None:self.puncher_status = "? 還未到打卡時間,腳本自動結束"print("? 還未到打卡時間,腳本自動結束")else:self.puncher_status = "? 獲取問卷失敗,請稍后重試"print("? 獲取問卷失敗,請稍后重試")return 0if filling_status is False:self.puncher_status = "? 今天暫未打卡,嘗試進行打卡"self.check_in_detail(str(id))else:self.puncher_status = "? 今天已經打卡,腳本自動結束"print("? 今天已經打卡,腳本自動結束")return 0except 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 0except Exception as e:print("? 獲取問卷詳情失敗")def check_in_save(self):try:url = "/ly-pd-mb/form/api/answerSheet/saveNormal"header = self.headerheader["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()
自動打卡的實現則需要去部署騰訊云函數(其它廠商的也行),在云函數中設置執行周期。相關的實現教程請前往云函數部署教程。