forked from kottory/NJU-health-report
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
62 lines (50 loc) · 2.03 KB
/
run.py
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
from njupass import NjuUiaAuth
from dotenv import load_dotenv
import os
import json
import time
import logging
URL_JKDK_LIST = 'http://ehallapp.nju.edu.cn/xgfw/sys/yqfxmrjkdkappnju/apply/getApplyInfoList.do'
URL_JKDK_APPLY = 'http://ehallapp.nju.edu.cn/xgfw/sys/yqfxmrjkdkappnju/apply/saveApplyInfos.do'
auth = NjuUiaAuth()
if __name__ == "__main__":
load_dotenv(verbose=True)
logging.basicConfig(
level=logging.INFO, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
log = logging.getLogger()
username = os.getenv('NJU_USERNAME')
password = os.getenv('NJU_PASSWORD')
curr_location = os.getenv('CURR_LOCATION')
if username == '' or password == '' or curr_location == '':
log.error('账户、密码或地理位置信息为空!请检查是否正确地设置了 SECRET 项(GitHub Action)。')
os._exit(1)
log.info('尝试登录...')
if auth.needCaptcha(username):
log.error("统一认证平台需要输入验证码才能继续,请手动登录后再重试")
os._exit(1)
ok = auth.login(username, password)
if not ok:
log.error("登录失败,可能是密码错误或网络问题。")
os._exit(1)
log.info('登录成功!')
for count in range(10):
log.info('尝试获取打卡列表信息...')
r = auth.session.get(URL_JKDK_LIST)
if r.status_code != 200:
log.error('获取失败,一分钟后再次尝试...')
time.sleep(60)
continue
dk_info = json.loads(r.text)['data'][0]
if dk_info['TBZT'] == "0":
wid = dk_info['WID']
data = "?WID={}&IS_TWZC=1&CURR_LOCATION={}&JRSKMYS=1&IS_HAS_JKQK=1&JZRJRSKMYS=1".format(
wid, curr_location)
url = URL_JKDK_APPLY + data
log.info('正在打卡')
auth.session.get(url)
time.sleep(1)
else:
log.info("今日已打卡!")
os._exit(0)
log.error("打卡失败,请尝试手动打卡")
os._exit(-1)