-
Notifications
You must be signed in to change notification settings - Fork 1
/
checker-daemon.py
86 lines (80 loc) · 2.98 KB
/
checker-daemon.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# encoding: utf-8
from bs4 import BeautifulSoup
import requests
import time, configparser, os, random
import toolsPack
logger = toolsPack.logger
pushInfo = toolsPack.pushInfo
# 初始化
try:
with open('info.ini') as f:
pass
except FileNotFoundError:
print(logger(1, '正在初始化'))
cookie = toolsPack.cookiesHander()
status = toolsPack.infoGen(cookie)
if status:
info = '初始化成功,请检查并完善 info.ini 文件,以便下次运行,详见 readme 文件'
print(logger(1, info))
else:
info = '初始化失败'
print(logger(-1, info))
exit(0)
def check(cookie,data):
response = requests.post('http://yun.ujs.edu.cn/xxhgl/yqsb/grmrsb',\
headers = toolsPack.headers, cookies=cookie, data=data)
soup = BeautifulSoup(response.text, 'html.parser')
try:
msg = soup.find_all('h2')[1].string
except IndexError:
return {'err' : 1}
return {'err' : 0, 'msg' : msg}
while True:
config = configparser.ConfigParser()
config.optionxform = str
config.read('conf.ini')
# 打卡
checkTime = int(config['global']['checkTime'])
now = int(time.strftime('%H'))
if now == checkTime:
print(logger(1,'进入打卡流程'))
while True:
cookie = toolsPack.cookiesHander()
loginStatus = toolsPack.getStatus(cookie)
if loginStatus == -1:
info = '服务器维护中,20分钟后重试'
print(logger(-1,info))
pushInfo(info, '')
time.sleep(20*60)
continue
elif loginStatus == -2:
info = 'cookie无效导致登陆失败,20分钟后重试'
print(logger(-1, info))
pushInfo(info, '')
time.sleep(20*60)
continue
# 提交表单
data = toolsPack.dataHander()
# 体温接口
if config['global']['temperatureSource'] == 'randomNomral':
data['xwwd'] = round(random.uniform(36.3, 37.2),1)
data['swwd'] = round(random.uniform(36.3, 37.2),1)
elif config['global']['temperatureSource'] == 'manual':
data['xwwd'] = config['tempData']['amTemp']
data['swwd'] = config['tempData']['pmTemp']
checkStatus = check(cookie, data)
print(logger(2, 'POST DATA:' + str(data)))
if checkStatus['err']:
info = '收到服务器端不正确的回复,请检查,20分钟后重试'
print(logger(-1, info))
pushInfo(info, '')
time.sleep(20*60)
continue
else:
info = '打卡成功\^o^/'
print(logger(1, info + '返回消息: ' + checkStatus['msg']))
pushInfo(info, '返回消息: ' + checkStatus['msg'])
break
time.sleep(60*60) # 好梦
time.sleep(60*60)
print(logger(1, '等待打卡'))