Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to fix bugs in starring #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions clock-in.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import sys
# import ddddocr


class ClockIn(object):
"""Hit card class

Attributes:
username: (str) 浙大统一认证平台用户名(一般为学号)
password: (str) 浙大统一认证平台密码
Expand All @@ -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"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -159,6 +154,7 @@ class DecodeError(Exception):

def main(username, password):
"""Hit card process

Arguments:
username: (str) 浙大统一认证平台用户名(一般为学号)
password: (str) 浙大统一认证平台密码
Expand Down Expand Up @@ -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
Expand Down