-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathleave.py
executable file
·328 lines (287 loc) · 15.4 KB
/
leave.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# coding: utf-8
# Author:quzard
import datetime
import json
import re
from urllib import parse
import execjs
import requests
from random import randint
USER_AGENTS = [
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
"Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
"Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0",
"Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20",
"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52",
]
class Leave(object):
def __init__(self, uname, pwd, path):
self.uname = uname
self.pwd = pwd
self.path = path
if self.uname[:3] == "213":
self.undergraduate = True
self.urlBegin = 'http://ehall.seu.edu.cn/xsfw/sys/xsqjapp/'
self.cookie_url = 'http://ehall.seu.edu.cn/xsfw/sys/swpubapp/indexmenu/getAppConfig.do?appId=4810794463325921&appName=xsqjapp'
else:
self.undergraduate = False
self.urlBegin = 'http://ehall.seu.edu.cn/ygfw/sys/xsqjappseuyangong/'
self.cookie_url = 'http://ehall.seu.edu.cn/ygfw/sys/swpubapp/indexmenu/getAppConfig.do?appId=5869188708264821&appName=xsqjappseuyangong&v=06154290794922301'
# 登陆
def login(self):
login_url = self.urlBegin + '*default/index.do'
get_login = self.sess.get(login_url)
get_login.encoding = 'utf-8'
lt = re.search('name="lt" value="(.*?)"', get_login.text).group(1)
salt = re.search('id="pwdDefaultEncryptSalt" value="(.*?)"', get_login.text).group(1)
execution = re.search('name="execution" value="(.*?)"', get_login.text).group(1)
f = open(self.path + "/encrypt.js", 'r', encoding='UTF-8')
line = f.readline()
js = ''
while line:
js = js + line
line = f.readline()
ctx = execjs.compile(js)
password = ctx.call('_ep', self.pwd, salt)
login_post_url = 'https://newids.seu.edu.cn/authserver/login?service=http%3A%2F%2Fehall.seu.edu.cn%2Fygfw%2Fsys%2Fxsqjappseuyangong%2F*default%2Findex.do'
personal_info = {'username': self.uname,
'password': password,
'lt': lt,
'dllt': 'userNamePasswordLogin',
'execution': execution,
'_eventId': 'submit',
'rmShown': '1'}
post_login = self.sess.post(login_post_url, personal_info)
post_login.encoding = 'utf-8'
if re.search("出校登记审批", post_login.text):
return "登陆成功!"
else:
print(post_login.text)
return "登陆失败!"
# 设置self.header
def getheader(self):
get_cookie = self.sess.get(self.cookie_url)
cookie = requests.utils.dict_from_cookiejar(self.sess.cookies)
c = ""
for key, value in cookie.items():
c += key + "=" + value + "; "
self.header = {'Referer': self.urlBegin + '*default/index.do',
'Cookie': c}
# 获取之前信息
def get_info(self):
personal_info_url = self.urlBegin + 'modules/wdqj/wdqjbg.do'
get_personal_info = self.sess.post(personal_info_url, data={'XSBH': str(self.uname), 'pageSize': '100', 'pageNumber': '1'},
headers=self.header)
return get_personal_info
def get_info_2(self, SQBH):
url = self.urlBegin + 'modules/wdqj/qjxqbd.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
FormData = {'SQBH': SQBH}
data = parse.urlencode(FormData)
get_personal_info = self.sess.post(url, data=data,
headers=self.header)
get_personal_info = json.loads(get_personal_info.text)['datas']['qjxqbd']['rows']
get_personal_info = get_personal_info[0]
return get_personal_info
# 获取未销假
def getAllNoRemoveLeave(self):
if self.undergraduate:
url = self.urlBegin + 'modules/leaveApply/getNoRemoveLeave.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
FormData = {"requestParamStr": {}}
data = parse.urlencode(FormData)
else:
url = self.urlBegin + 'modules/leaveApply/getAllNoRemoveLeave.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
FormData = {"requestParamStr": {'XSBH': str(self.uname)}}
data = parse.urlencode(FormData)
get_personal_info = self.sess.post(url, data=data, headers=self.header)
if "data" in get_personal_info.text:
datas = json.loads(get_personal_info.text)['data']
return self.addXjApply(datas)
return False
# 销假
def addXjApply(self, datas):
if self.undergraduate:
url = self.urlBegin + 'modules/xjset/xjshApply.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
now_time = datetime.datetime.now()
data = datas
if now_time.strftime("%Y-%m-%d") not in data['QJKSRQ'] and (now_time + datetime.timedelta(days=+1)).strftime(
"%Y-%m-%d") not in data['QJKSRQ']:
print("销假: ", data["QJKSRQ"])
post_info = {"requestParamStr": {"SQBH": data["SQBH"]}}
data = parse.urlencode(post_info)
get_personal_info = self.sess.post(url, data=data, headers=self.header)
else:
if (now_time + datetime.timedelta(days=+1)).strftime("%Y-%m-%d") in data['QJKSRQ']:
return True
return False
else:
url = self.urlBegin + 'modules/leaveApply/addXjApply.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
for data in datas:
now_time = datetime.datetime.now()
if now_time.strftime("%Y-%m-%d") not in data['QJKSRQ'] and (now_time + datetime.timedelta(days=+1)).strftime(
"%Y-%m-%d") not in data['QJKSRQ']:
print("销假: ", data["QJKSRQ"])
post_info = {
"data": {"SQBH": "", "XSBH": 0, "SHZT": "99", "XJFS": "2",
"XJSJ": "", "XJRQ": "", "SQR": "", "SQRXM": "",
"THZT": "0"}}
post_info["data"]["SQBH"] = data["SQBH"]
post_info["data"]["XSBH"] = int(data["XSBH"])
post_info["data"]["XJSJ"] = now_time.strftime("%Y-%m-%d %H:%M:%S")
post_info["data"]["XJRQ"] = now_time.strftime("%Y-%m-%d")
post_info["data"]["SQR"] = data["XSBH"]
post_info["data"]["SQRXM"] = data["XM"]
data = parse.urlencode(post_info)
get_personal_info = self.sess.post(url, data=data, headers=self.header)
else:
if (now_time + datetime.timedelta(days=+1)).strftime("%Y-%m-%d") in data['QJKSRQ']:
return True
return False
# 获取未审批
def getAllApplyedLeave(self):
url = self.urlBegin + 'modules/leaveApply/getAllApplyedLeave.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
FormData = {"requestParamStr": {'XSBH': str(self.uname)}}
data = parse.urlencode(FormData)
get_personal_info = self.sess.post(url, data=data, headers=self.header)
if "data" in get_personal_info.text:
datas = json.loads(get_personal_info.text)['data']
return self.backleaveApply(datas)
return False
# 撤回
def backleaveApply(self, datas):
url = self.urlBegin + 'modules/leaveApply/backleaveApply.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
for data in datas:
now_time = datetime.datetime.now()
# 未审批的今天和明天的不撤回
if now_time.strftime("%Y-%m-%d") not in data['QJKSRQ'] and (now_time + datetime.timedelta(days=+1)).strftime(
"%Y-%m-%d") not in data['QJKSRQ']:
print("撤回: ", data["QJKSRQ"])
post_info = {"requestParamStr": {"SQBH": data["SQBH"]}}
data = parse.urlencode(post_info)
get_personal_info = self.sess.post(url, data=data, headers=self.header)
else:
return True
return False
# 删除草稿
def delleaveApply(self, datas):
url = self.urlBegin + 'modules/leaveApply/delleaveApply.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
for data in datas:
if data["SHZT_DISPLAY"] == "草稿":
if self.undergraduate == False:
print("状态: ",data["SHZT_DISPALY_DISPLAY"])
print("删除草稿: ", data["QJKSRQ"])
post_info = {"requestParamStr": {"SQBH": data["SQBH"]}}
data = parse.urlencode(post_info)
get_personal_info = self.sess.post(url, data=data, headers=self.header)
def askForLeave(self):
# 设置header
self.getheader()
# 获取未销假
r = self.getAllNoRemoveLeave()
if r:
return "请假成功! 已经存在未销假的请假"
# 获取未审批
r = self.getAllApplyedLeave()
if r:
return "请假成功! 已经存在未审批的请假"
# 删除草稿
get_personal_info = self.get_info()
raw_personal_info = json.loads(get_personal_info.text)['datas']['wdqjbg']['rows']
self.delleaveApply(raw_personal_info)
get_personal_info = self.get_info()
if get_personal_info.status_code == 200:
print('获取前一日信息成功!')
else:
print("获取信息失败!")
return "获取信息失败!"
infos = json.loads(get_personal_info.text)['datas']['wdqjbg']['rows']
if len(infos) == 0:
print("之前没有上报!")
return "之前没有上报!"
raw_personal_info = []
for info in infos:
if info['DZQJSY_DISPLAY'] == "因事出校(当天往返)" or info['DZQJSY_DISPLAY'] == "离校(短期科研实验)" or info['DZQJSY_DISPLAY'] == "就业出校(当天往返)":
raw_personal_info = info
break
if len(raw_personal_info) == 0:
print("之前没有上报!")
return "之前没有上报!"
raw_personal_info = self.get_info_2(raw_personal_info["SQBH"])
datas = {"QJLX_DISPLAY": "不涉及职能部门", "QJLX": "3bc0d68330fd4d869152238251b867ee", "DZQJSY_DISPLAY": "因事出校(当天往返)",
"DZQJSY": "763ec35f8f5545c0aa245e8fbc20adb2", "QJXZ_DISPLAY": "因公", "QJXZ": "2", "QJFS_DISPLAY": "请假",
"QJFS": "1", "YGLX_DISPLAY": "实验", "YGLX": "3", "SQSM": "", "QJKSRQ": "",
"QJJSRQ": "", "QJTS": "1", "QJSY": "去无线谷科研", "ZMCL": "", "SJH": "",
"DZSFLX_DISPLAY": "是", "DZSFLX": "1", "HDXQ_DISPLAY": "九龙湖校区", "HDXQ": "1", "DZSFLN_DISPLAY": "否",
"DZSFLN": "0", "DZSFLKJSS_DISPLAY": "", "DZSFLKJSS": "", "DZ_SFCGJ_DISPLAY": "", "DZ_SFCGJ": "",
"DZ_GJDQ_DISPLAY": "", "DZ_GJDQ": "", "QXSHEN_DISPLAY": "", "QXSHEN": "", "QXSHI_DISPLAY": "", "QXSHI": "",
"QXQ_DISPLAY": "", "QXQ": "", "QXJD": "", "XXDZ": "无线谷", "JTGJ_DISPLAY": "", "JTGJ": "", "CCHBH": "",
"SQBH": "", "XSBH": "", "JJLXR": "", "JJLXRDH": "",
"JZXM": "", "JZLXDH": "", "DSXM": "", "DSDH": "", "FDYXM": "",
"FDYDH": "", "SFDSQ": "0"}
post_info = {}
for key, value in datas.items():
if key in raw_personal_info:
if raw_personal_info[key] == 'null' or raw_personal_info[key] == None:
post_info[key] = ''
else:
post_info[key] = raw_personal_info[key]
else:
post_info[key] = value
if post_info['QJSY'] == '':
post_info['QJSY'] = "去无线谷科研"
if post_info['XXDZ'] == '':
post_info['XXDZ'] = "去无线谷科研"
post_info['SQBH'] = ''
now_time = datetime.datetime.now()
post_info["QJKSRQ"] = (now_time + datetime.timedelta(days=+1)).strftime("%Y-%m-%d 06:00")
post_info["QJJSRQ"] = (now_time + datetime.timedelta(days=+1)).strftime("%Y-%m-%d 23:59")
save_url = self.urlBegin + 'modules/leaveApply/addLeaveApply.do'
self.header['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
FormData = {'data': post_info}
data = parse.urlencode(FormData)
try:
save = self.sess.post(save_url, data=data, headers=self.header)
except:
print("上报超时!")
return "上报超时!"
if "成功" in save.text:
print('请假成功!')
return '请假成功!'
else:
print("请假失败!")
return "请假失败!"
def do_report(self):
self.sess = requests.session()
random_agent = USER_AGENTS[randint(0, len(USER_AGENTS)-1)]
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'DNT': '1',
'Proxy-Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'User-Agent': random_agent,
}
self.sess.headers = headers
if self.login() == "登陆失败!":
return "登陆失败!"
msg = self.askForLeave()
self.sess.close()
return msg