From db28942fcfac2277706945f17a163df4d6e79459 Mon Sep 17 00:00:00 2001 From: JIANGBOFENG <52899360+JIANGBOFENG@users.noreply.github.com> Date: Fri, 30 Sep 2022 09:36:38 +0800 Subject: [PATCH] update to fix bugs in starring fix bugs when starring. --- clock-in.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/clock-in.py b/clock-in.py index be71912..217a11b 100644 --- a/clock-in.py +++ b/clock-in.py @@ -10,9 +10,9 @@ import sys # import ddddocr - class ClockIn(object): """Hit card class + Attributes: username: (str) 浙大统一认证平台用户名(一般为学号) password: (str) 浙大统一认证平台密码 @@ -25,16 +25,14 @@ class ClockIn(object): LOGIN_URL = "https://zjuam.zju.edu.cn/cas/login?service=https%3A%2F%2Fhealthreport.zju.edu.cn%2Fa_zju%2Fapi%2Fsso%2Findex%3Fredirect%3Dhttps%253A%252F%252Fhealthreport.zju.edu.cn%252Fncov%252Fwap%252Fdefault%252Findex" BASE_URL = "https://healthreport.zju.edu.cn/ncov/wap/default/index" SAVE_URL = "https://healthreport.zju.edu.cn/ncov/wap/default/save" - CAPTCHA_URL = 'https://healthreport.zju.edu.cn/ncov/wap/default/code' + # captcha_url = "https://healthreport.zju.edu.cn/ncov/wap/default/code" HEADERS = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" } - def __init__(self, username, password): self.username = username self.password = password self.sess = requests.Session() -# self.ocr = ddddocr.DdddOcr() def login(self): """Login to ZJU platform""" @@ -69,19 +67,15 @@ def get_date(self): today = datetime.date.today() return "%4d%02d%02d" % (today.year, today.month, today.day) -# def get_captcha(self): -# """Get CAPTCHA code""" -# resp = self.sess.get(self.CAPTCHA_URL) -# captcha = self.ocr.classification(resp.content) -# print("验证码:", captcha) -# return captcha - def get_info(self, html=None): """Get hitcard info, which is the old info with updated new time.""" if not html: res = self.sess.get(self.BASE_URL, headers=self.HEADERS) html = res.content.decode() - + # 新建ocr,并读取验证码进行识别 + # ocr = ddddocr.DdddOcr(old=True) + # resp = self.sess.get(self.captcha_url, headers=self.HEADERS) + # captcha = ocr.classification(resp.content) try: old_infos = re.findall(r'oldInfo: ({[^\n]+})', html) if len(old_infos) != 0: @@ -118,12 +112,13 @@ def get_info(self, html=None): new_info['gwszdd'] = "" new_info['szgjcs'] = "" - # 2022.05.07 - # new_info['verifyCode'] = self.get_captcha() # 验证码识别(已取消) + # add in 2022.07.08 + new_info['sfymqjczrj'] = 2 #同住人员是否发热 + new_info['ismoved'] = 4 #是否有离开 + new_info['internship'] = 3 #是否进行实习 + new_info['sfcxzysx'] = 2 #是否涉及疫情管控 - # 2022.07.05 - new_info['internship'] = 3 # 今日是否进行实习或实践 - + # new_info['verifyCode'] = captcha # 2021.08.05 Fix 2 magics = re.findall(r'"([0-9a-f]{32})":\s*"([^\"]+)"', html) for item in magics: @@ -159,6 +154,7 @@ class DecodeError(Exception): def main(username, password): """Hit card process + Arguments: username: (str) 浙大统一认证平台用户名(一般为学号) password: (str) 浙大统一认证平台密码 @@ -194,13 +190,17 @@ def main(username, password): print(res['m']) if res['m'].find("已经") != -1: # 已经填报过了 不报错 pass - elif res['m'].find("验证码错误") != -1: # 验证码错误 - print('再次尝试') - time.sleep(5) - main(username, password) - pass else: - raise Exception + count = 0 + while (str(res['e']) != '0' and count < 3): + time.sleep(5) + dk.get_info() + res = dk.post() + count +=1 + if str(res['e']) == '0': + print('已为您打卡成功!') + else: + raise Exception except Exception: print('数据提交失败') raise Exception