Skip to content

Commit a60e4e9

Browse files
committed
Update YdszTool.py
1 parent 63f78a5 commit a60e4e9

File tree

1 file changed

+46
-31
lines changed

1 file changed

+46
-31
lines changed

YdszTool.py

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def main_run():
101101
if self.r1_type.get() == 'F':
102102
try:
103103
self.login()
104+
win.update()
104105
win.destroy()
105106
self.main()
106107
except Exception as e:
@@ -110,25 +111,31 @@ def main_run():
110111
print('登录失败')
111112
print('错误信息:', e)
112113
else:
113-
start_time = datetime.now()
114-
end_time = text4.get() + ' ' + box6.get() + ':' + box7.get() + ':' + '00'
115-
end_time = datetime.strptime(end_time, '%Y-%m-%d %H:%M:%S')
116-
seconds = (end_time - start_time).total_seconds()
117-
win.destroy()
118-
if seconds > 120:
119-
print('开始倒计时,将在' + str(end_time.strftime('%Y-%m-%d %H:%M:%S')) + '两分钟前开始预约')
120-
seconds -= 120
121-
while seconds > 0:
122-
print('距离开始运行还有' + str(int(seconds // 3600)) + '小时' + str(int(
123-
(seconds - 3600 * (seconds // 3600)) // 60)) + '分钟')
124-
sleep(60)
125-
seconds -= 60
126-
sec_run()
127-
elif seconds > 0:
128-
sec_run()
114+
text4_time = text4.get()
115+
if len(text4_time) == 10 and text4_time[4] == '-' and text4_time[7] == '-':
116+
start_time = datetime.now()
117+
end_time = text4.get() + ' ' + box6.get() + ':' + box7.get() + ':' + '00'
118+
end_time = datetime.strptime(end_time, '%Y-%m-%d %H:%M:%S')
119+
seconds = (end_time - start_time).total_seconds()
120+
win.update()
121+
win.destroy()
122+
if seconds > 120:
123+
print('开始倒计时,将在' + str(end_time.strftime('%Y-%m-%d %H:%M:%S')) + '两分钟前开始预约')
124+
seconds -= 120
125+
while seconds > 0:
126+
print('距离开始预约还有' + str(int(seconds // 3600)) + '小时' + str(int(
127+
(seconds - 3600 * (seconds // 3600)) // 60)) + '分钟')
128+
sleep(60)
129+
seconds -= 60
130+
sec_run()
131+
else:
132+
print('预约开始时间小于两分钟或当前时间,将直接开始预约')
133+
sec_run()
129134
else:
130-
print('预约开始时间小于当前时间')
131-
return
135+
print('开始时间格式错误,将直接开始预约')
136+
win.update()
137+
win.destroy()
138+
sec_run()
132139
except Exception as e:
133140
print('登录失败')
134141
print('错误信息:', e)
@@ -250,6 +257,7 @@ def random_string(length):
250257
raw = tmp.encode()
251258
cipher = AES.new(key, AES.MODE_CBC, iv)
252259
return b64encode(cipher.encrypt(raw))
260+
253261
# 登录请求
254262
login_url = 'https://authserver.szpt.edu.cn/authserver/login?service=' \
255263
'https%3A%2F%2Fydsz.szpt.edu.cn%3A443%2Fcas%2Flogin'
@@ -291,7 +299,18 @@ def main(self):
291299
timelst.append(i + ':00')
292300
else:
293301
print('请检查时间参数')
294-
return
302+
return 2
303+
# 获取卡ID和卡余额
304+
url_get = 'https://ydsz.szpt.edu.cn/easyserpClient/card/getCardByUser?shopNum=' + \
305+
self.shopNum + '&token=' + self.token
306+
try:
307+
carddate = loads(get(url_get, headers={'Accept': 'application/json, text/plain, */*'}, verify=False)
308+
.text)['data'][0]
309+
cardid = carddate['cardindex']
310+
cardcash = carddate['cardcash']
311+
except Exception as e:
312+
print('获取校园卡数据失败,错误信息为:' + str(e))
313+
return 2
295314
# 构造数据
296315
data_post = []
297316
money = 0
@@ -303,10 +322,12 @@ def main(self):
303322
verify=False).text)['data']['placeArray']
304323
except Exception as e:
305324
print('获取场地信息失败,错误信息为:' + str(e))
306-
return
325+
return 2
307326
for i in data:
308327
for j in i['projectInfo']:
309328
if j['state'] == 1 and j['starttime'] in timelst and num < self.max_site:
329+
if j['money'] + money > cardcash:
330+
break
310331
timelst.remove(j['starttime'])
311332
data_post.append({"day": self.day, "startTime": j["starttime"], "endTime": j["endtime"],
312333
"placeShortName": i["projectName"]["shortname"],
@@ -316,15 +337,6 @@ def main(self):
316337
if not data_post:
317338
print('没有可用场地')
318339
return
319-
# 获取卡ID
320-
url_get = 'https://ydsz.szpt.edu.cn/easyserpClient/card/getCardByUser?shopNum=' + \
321-
self.shopNum + '&token=' + self.token
322-
try:
323-
cardid = loads(get(url_get, headers={'Accept': 'application/json, text/plain, */*'}, verify=False)
324-
.text)['data'][0]['cardindex']
325-
except Exception as e:
326-
print('获取卡ID失败,错误信息为:' + str(e))
327-
return
328340
# 提交数据
329341
url_post = 'https://ydsz.szpt.edu.cn/easyserpClient/place/reservationPlace'
330342
post_data = 'token=' + self.token + '&shopNum=' + self.shopNum + '&fieldinfo=' + urllib.parse.quote(str(
@@ -335,20 +347,23 @@ def main(self):
335347
result = loads(post(url_post, headers={'Accept': 'application/json, text/plain, */*'}, verify=False,
336348
params=post_data).text)
337349
if result.get('msg') == 'success':
338-
print('预定成功,共计' + str(num) + '个场地,' + str(money) + '元')
350+
print(datetime.now().strftime('%H:%M:%S') + '预定成功,共计' + str(num) + '个场地,' + str(money) + '元')
339351
print('场地信息:')
340352
for i in data_post:
341353
print(i['name'] + ' ' + i['startTime'] + '-' + i['endTime'])
342-
input('程序结束,按回车键退出')
343354
return 1
344355
elif result.get('msg') == 'fail':
345356
print('预定失败,错误信息为:' + result.get('data'))
357+
return 2
346358
else:
347359
print('预定失败,错误信息为:' + str(result.get('status'), str(result.get('error'))))
360+
return 2
348361
except Exception as e:
349362
print('预定失败')
350363
print('错误信息:' + str(e))
364+
return 2
351365

352366

353367
if __name__ == '__main__':
354368
run = Ydsz()
369+
input('程序结束,按回车键退出')

0 commit comments

Comments
 (0)