forked from WeiJiuguo/Wanmei_AutoCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
209 lines (200 loc) · 6.29 KB
/
main.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import time
import json
import requests
import random
import datetime
import os
#json读取函数
def GetFromJSON(filename):
flag = False
idStr={}
try:
j_file=open(filename,'r', encoding='utf8')
idStr=json.load(j_file)
flag=True
except:
print('从%s读取JSON数据出错!'%filename)
finally:
if flag:
j_file.close()
return idStr
#读取text.json文件
filename = r'text.json'
jsonDic = GetFromJSON(filename)
AllClass = jsonDic['data']['classAll']
def main():
#sectets字段录入
userName = []
stuNum = []
text = []
sckey = []
success = []
failure = []
result = []
#多人循环录入
while True:
try:
users = input()
info = users.split(',')
userName.append(info[0])
stuNum.append(info[1])
text.append(info[2])
sckey.append(info[3])
except:
break
#早中午判断
nowTime = (time.localtime().tm_hour + 8 ) % 24
if (nowTime >= 6) & (nowTime < 8):
templateid = "clockSign1"
RuleId = 146
elif (nowTime >= 11) & (nowTime < 15):
templateid = "clockSign2"
RuleId = 147
elif (nowTime >= 21) & (nowTime< 22):
templateid = "clockSign3"
RuleId = 148
else:
print("现在时间%d点%d分,打卡时间未到!" %(nowTime,time.localtime().tm_min))
exit(0)
#提交打卡
for index,value in enumerate(stuNum):
print("开始获取用户%sDeptId"%(value[-6:]))
count = 0
while (count < 3):
try:
response = check_in(text[index],stuNum[index],userName[index],RuleId,templateid)
if response.json()["msg"] == '成功'and count == 0:
strTime = GetNowTime()
success.append(value[-6:])
print(response.text)
msg = value[-6:]+"打卡成功-" + strTime
result=response
break
elif response.json()["msg"] == '成功':
strTime = GetNowTime()
success.append(value[-6:])
print(response.text)
msg = value[-6:]+"打卡成功-" + strTime
break
else:
strTime = GetNowTime()
failure.append(value[-6:])
print(response.text)
msg = value[-6:] + "打卡异常-" + strTime
count = count + 1
print('%s打卡失败,开始第%d次重试...'%(value[-6:],count))
time.sleep(15)
except:
print("服务器错误!")
failure.append(value[-6:])
msg = "请仔细检查USERS!"
break
print(msg)
print("-----------------------")
fail = sorted(set(failure),key=failure.index)
strTime = GetNowTime()
title = "%s人打卡成功,%s人打卡失败-"%(len(success),len(fail)) + strTime
try:
if len(sckey[0])>2:
print('主用户开始微信推送...')
WechatPush(title,sckey[0],success,fail,result)
except:
print("Maybe主用户打卡失败!")
def GetNowTime():
cstTime = (datetime.datetime.utcnow() + datetime.timedelta(hours=8))
strTime = cstTime.strftime("%H:%M:%S")
return strTime
#班级获取函数
def GetDeptId(text):
try:
TextStr = text.split('-', 3)
ClassName = TextStr[2]
# 获取deptId
except:
print("获取失败,请检查格式")
try:
for Class in AllClass:
if (Class['name'] == ClassName):
deptId = Class['deptId']
if deptId:
print('获取deptId成功!')
except:
print("获取deptId失败!")
exit(1)
return deptId
#打卡参数配置函数
def GetUserJson(deptId,text,stuNum,userName,RuleId,templateid):
#随机温度(36.2~36.8)
a=random.uniform(36.2,36.8)
temperature = round(a, 1)
return {
"businessType": "epmpics",
"method": "submitUpInfoSchool",
"jsonData": {
"deptStr": {
"deptid": deptId,
"text": text
},
"areaStr": {"streetNumber":"","street":"长椿路辅路","district":"中原区","city":"郑州市","province":"河南省","town":"","pois":"河南工业大学(莲花街校区)","lng":113.55064699999795 + random.random()/1000,"lat":34.83870696238093 + random.random()/1000,"address":"中原区长椿路辅路河南工业大学(莲花街校区)","text":"河南省-郑州市","code":""},
"reportdate": round(time.time()*1000),
"customerid": "43",
"deptid": deptId,
"source": "app",
"templateid": templateid,
"stuNo": stuNum,
"username": userName,
"userid": round(time.time()),
"updatainfo": [
{
"propertyname": "temperature",
"value": temperature
},
{
"propertyname": "symptom",
"value": "无症状"
}
],
"customerAppTypeRuleId": RuleId,
"clockState": 0
},
}
#打卡提交函数
def check_in(text,stuNum,userName,RuleId,templateid):
deptId = GetDeptId(text)
sign_url = "https://reportedh5.17wanxiao.com/sass/api/epmpics"
jsons=GetUserJson(deptId,text,stuNum,userName,RuleId,templateid)
#提交打卡
response = requests.post(sign_url, json=jsons)
return response
#微信通知
def WechatPush(title,sckey,success,fail,result):
page = json.dumps(result.json(), sort_keys=True, indent=4, separators=(',', ': '),ensure_ascii=False)
content = f"""
### 打卡成功用户:
```
{success}
```
### 打卡失败用户:
```
{fail}
```
### 主用户打卡信息:
```
{page}
```
### 😀[收藏](https://github.com/YooKing/HAUT_autoCheck)此项目
"""
data = {
"text":title,
"desp":content
}
try:
req = requests.post(sckey,data = data)
if req.json()["errmsg"] == 'success':
print("Server酱推送服务成功")
else:
print("Server酱推送服务失败")
except:
print("微信推送参数错误")
if __name__ == '__main__':
main()