1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
import json import requests import random import time
useragentlist = [ "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.14) Gecko/20110218 AlexaToolbar/alxf-2.0 Firefox/3.6.14" ]
temperature = ["36\"C~36.5°C", "36.5°C~36.9°C"]
class User: def __init__(self, sn, idCard): self.sn = sn self.idCard = idCard
def parseJSON(dct): if isinstance(dct, dict): user = User(str(dct["sn"]), str(dct["idCard"])) return user return dct
def readJson(): fileName = 'jsons/user.json' with open(fileName, 'r', encoding='utf-8') as f: userList = json.load(f) if isinstance(userList, dict): users = userList["users"] for i in range(len(users)): users[i] = User.parseJSON(users[i]) return users
def writeError(logs): fileName = 'logs/error.log' with open(fileName, 'a', encoding='utf-8') as f: f.write(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + ': ') f.write(logs)
def writeLog(logs): fileName = 'logs/run.log' with open(fileName, 'a', encoding='utf-8') as f: f.write(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + ': ') f.write(logs)
def request_sessionId(json_data): url = "https://zhxg.whut.edu.cn/yqtjwx/api/login/checkBind" headers = { "Accept-Encoding": "gzip, deflate, br", "content-type": "application/json", "Referer": "https://servicewechat.com/wxa0738e54aae84423/17/page-frame.html", "X-Tag": "flyio", "Accept-Language": "zh-cn", "Connection": "keep - alive", "Host": "zhxg.whut.edu.cn" } headers['User-Agent'] = random.choice(useragentlist) r = requests.post(url=url, headers=headers, json=json_data) result = json.loads(r.text) sessionId = result['data']['sessionId']
if result["status"] != True : writeError("StudentId: " + str(json_data["sn"]) + " SessionId: " + str(sessionId) + " Error: 登录失败\n") writeError(str(result) + "\n") else : writeLog("StudentId: " + str(json_data["sn"]) + " SessionId: " + str(sessionId) + " Data: 登录成功\n") return str(sessionId)
def request_bindUserInfo(sessionId, json_data): url = "https://zhxg.whut.edu.cn/yqtjwx/api/login/bindUserInfo" headers = { "Accept-Encoding": "gzip, deflate, br", "content-type": "application/json", "Referer": "https://servicewechat.com/wxa0738e54aae84423/17/page-frame.html", "Cookie": "JSESSIONID=%s" % (sessionId), "Accept": "*/*", "X-Tag": "flyio", "Accept-Language": "zh-cn", "Connection": "keep - alive", "Host": "zhxg.whut.edu.cn" } headers['User-Agent'] = random.choice(useragentlist) r = requests.post(url=url, headers=headers, json=json_data) result = json.loads(r.text) if result["status"] != True : writeError("StudentId: " + str(json_data["sn"]) + " SessionId: " + str(sessionId) + " Error: 已被绑定\n") writeError(str(result) + "\n") else : writeLog("StudentId: " + str(json_data["sn"]) + " SessionId: " + str(sessionId) + " Data: 未被绑定\n")
def request_monitorRegister(sessionId, user_data, province, city, county, street): currentAddress = str(province) + str(city) + str(county) + str(street) url = "https://zhxg.whut.edu.cn/yqtjwx/./monitorRegister" headers = { "Accept-Encoding": "gzip, deflate, br", "content-type": "application/json", "Referer": "https://servicewechat.com/wxa0738e54aae84423/17/page-frame.html", "Cookie": "JSESSIONID=%s" % (sessionId), "Accept": "*/*", "X-Tag": "flyio", "Accept-Language": "zh-cn", "Connection": "keep - alive", "Host": "zhxg.whut.edu.cn" } headers['User-Agent'] = random.choice(useragentlist) json_data = { "diagnosisName": "", "relationWithOwn": "", "currentAddress": currentAddress, "remark": "", "healthInfo": "正常", "isDiagnosis": 0, "isFever": 0, "isInSchool": "1", "isLeaveChengdu": 0, "isSymptom": "0", "temperature": random.choice(temperature), "province": province, "city": city, "county": county } r = requests.post(url=url, headers=headers, json=json_data) result = json.loads(r.text) if result["status"] != True : writeError("StudentId: " + str(user_data["sn"]) + " SessionId: " + str(sessionId) + " Error: 打卡失败\n") writeError(str(result) + "\n") return False else : writeLog("StudentId: " + str(user_data["sn"]) + " SessionId: " + str(sessionId) + " Data: 打卡成功\n") return True
def cancelBind(sessionId, json_data): url = "https://zhxg.whut.edu.cn/yqtjwx/api/login/cancelBind" headers = { "Accept-Encoding": "gzip, deflate, br", "content-type": "application/json", "Referer": "https://servicewechat.com/wxa0738e54aae84423/17/page-frame.html", "Cookie": "JSESSIONID=%s" % (sessionId), "Connection": "keep - alive", "Host": "zhxg.whut.edu.cn" } headers['User-Agent'] = random.choice(useragentlist) r = requests.post(url=url, headers=headers) result = json.loads(r.text) if result["status"] != True : writeError("StudentId: " + str(json_data["sn"]) + " SessionId: " + str(sessionId) + " Error: 解绑失败\n") writeError(str(result) + "\n") else : writeLog("StudentId: " + str(json_data["sn"]) + " SessionId: " + str(sessionId) + " Data: 解绑成功\n")
if __name__ == '__main__': users = readJson() FLAG = True for u in users: data = {'sn': u.sn, 'idCard': u.idCard} id = request_sessionId(data) request_bindUserInfo(id, data) res = request_monitorRegister(id, data, "湖北省", "武汉市", "洪山区", "工大路") if res == False: print(time.strftime('%Y-%m-%d', time.localtime()) + ": 学号为: " + str(u.sn) + "的用户出现错误!") FLAG = False cancelBind(id, data) if FLAG == False: print(time.strftime('%Y-%m-%d', time.localtime()) + ": 每日填报完成,但存在错误!") else: print(time.strftime('%Y-%m-%d', time.localtime()) + ": 每日填报完成!")
|