Skip to content

Commit dc71470

Browse files
committed
Update YdszTool.py
1 parent 175f800 commit dc71470

File tree

1 file changed

+78
-136
lines changed

1 file changed

+78
-136
lines changed

YdszTool.py

Lines changed: 78 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from requests import get, post
1313
from Cryptodome.Cipher import AES
1414
from urllib3 import disable_warnings
15-
from tkinter import Tk, StringVar, Label, Entry, Button, ttk, END, Checkbutton, Frame
15+
from tkinter import Tk, StringVar, Label, Entry, Button, ttk, END
1616

1717

1818
class Ydsz:
@@ -22,35 +22,37 @@ def __init__(self):
2222
ssl._create_default_https_context = ssl._create_unverified_context
2323

2424
# 参数
25-
self.username, self.password, self.shopName, self.token, self.r1_type = '', '', '', '', ''
26-
self.day = '2022-11-06' # 日期
25+
self.username, self.password, self.shopName, self.token = '', '', '', ''
26+
self.day = '2022-11-29' # 日期
2727
self.starttime = 9 # 开始时间
2828
self.endtime = 12 # 结束时间
2929
self.max_site = 3 # 最多预约几小时
3030
self.shopNum = '1001' # 西丽湖:1001 留仙洞:1002
3131
self.post_type = '羽毛球'
3232

33-
self.win_box()
34-
35-
def win_box(self):
33+
def run(self):
3634
def func(event=None):
37-
if box1.get() == '西丽湖':
38-
box2['values'] = xm1
39-
box2.current(0)
35+
if xq_inp.get() == '西丽湖':
36+
xm_inp['values'] = xm1
37+
xm_inp.current(0)
4038
else:
41-
box2['values'] = xm2
42-
box2.current(0)
39+
xm_inp['values'] = xm2
40+
xm_inp.current(0)
4341

4442
def sec_run():
4543
flag = True
46-
print('开始预约')
44+
print('开始预约' + self.day[:4] + '年' + self.day[5:7] + '月' + self.day[8:] + '日' + str(self.starttime) +
45+
'-' + str(self.endtime) + '点' + self.post_type + str(self.max_site) + '小时场地')
4746
while True:
4847
try:
4948
self.login()
5049
break
5150
except Exception as e:
5251
if '由于目标计算机积极拒绝,无法连接。' in str(e):
53-
print('网站已关闭,正在重试...')
52+
print('一网通已关闭,正在重试...')
53+
sleep(2)
54+
elif '502' in str(e):
55+
print('韵动深职寄了,正在重试...')
5456
sleep(2)
5557
else:
5658
print('登录失败')
@@ -60,34 +62,34 @@ def sec_run():
6062
while flag:
6163
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
6264
for _ in range(100):
63-
if self.main():
65+
if self.send_info():
6466
flag = False
6567
break
6668

6769
def main_run():
68-
if len(text1.get()) == 8:
69-
self.username = text1.get()
70+
if len(xh_inp.get()) == 8:
71+
self.username = xh_inp.get()
7072
else:
7173
print('学号格式错误')
7274
return
73-
if len(text2.get()) > 7:
74-
self.password = text2.get()
75+
if len(mm_inp.get()) > 7:
76+
self.password = mm_inp.get()
7577
else:
7678
print('密码格式错误')
7779
return
78-
tmp_time = text3.get()
80+
tmp_time = rq_inp.get()
7981
if len(tmp_time) == 10 and tmp_time[4] == '-' and tmp_time[7] == '-':
8082
self.day = tmp_time
8183
else:
8284
print('日期格式错误')
8385
return
84-
if int(box3.get()) > int(box4.get()):
86+
if int(kssj_inp.get()) > int(jssj_inp.get()):
8587
print('开始时间大于结束时间')
8688
return
8789
else:
88-
self.starttime = int(box3.get())
89-
self.endtime = int(box4.get())
90-
self.max_site = int(box5.get())
90+
self.starttime = int(kssj_inp.get())
91+
self.endtime = int(jssj_inp.get())
92+
self.max_site = int(yysc_inp.get())
9193
if value1.get() == '西丽湖':
9294
self.shopNum = '1001'
9395
elif value1.get() == '留仙洞':
@@ -102,136 +104,75 @@ def main_run():
102104
self.shopName = 'lxd' + tmp_dict[self.post_type]
103105
self.post_type = '留仙洞' + self.post_type
104106
try:
105-
if self.r1_type.get() == 'F':
106-
try:
107-
self.login()
108-
win.update()
109-
win.destroy()
110-
self.main()
111-
except Exception as e:
112-
if '由于目标计算机积极拒绝,无法连接。' in str(e):
113-
print('网站已关闭,请稍后再试')
114-
else:
115-
print('登录失败')
116-
print('错误信息:', e)
117-
else:
118-
text4_time = text4.get()
119-
if len(text4_time) == 10 and text4_time[4] == '-' and text4_time[7] == '-':
120-
start_time = datetime.now()
121-
end_time = text4.get() + ' ' + box6.get() + ':' + box7.get() + ':' + '00'
122-
end_time = datetime.strptime(end_time, '%Y-%m-%d %H:%M:%S')
123-
seconds = (end_time - start_time).total_seconds()
124-
win.update()
125-
win.destroy()
126-
if seconds > 120:
127-
print('开始倒计时,将在' + str(end_time.strftime('%Y-%m-%d %H:%M:%S')) + '两分钟前开始预约')
128-
seconds -= 120
129-
while seconds > 0:
130-
print('距离开始预约还有' + str(int(seconds // 3600)) + '小时' + str(int(
131-
(seconds - 3600 * (seconds // 3600)) // 60)) + '分钟')
132-
sleep(60)
133-
seconds -= 60
134-
sec_run()
135-
else:
136-
print('预约开始时间小于两分钟或当前时间,将直接开始预约')
137-
sec_run()
138-
else:
139-
print('开始时间格式错误,将直接开始预约')
140-
win.update()
141-
win.destroy()
142-
sec_run()
107+
win.update()
108+
win.destroy()
109+
sec_run()
143110
except Exception as e:
144-
print('登录失败')
111+
print('订场失败')
145112
print('错误信息:', e)
146113

147114
win = Tk()
148115
win.title("韵动深职")
149-
width = 300
150-
height = 200
116+
width, height = 420, 130
151117
win.geometry("{}x{}+{}+{}".format(width, height, int((win.winfo_screenwidth() - width) / 2),
152118
int((win.winfo_screenheight() - height) / 2)))
153119
value1, value2, value3, value4, value5 = StringVar(), StringVar(), StringVar(), StringVar(), StringVar()
154120
xq = ['西丽湖', '留仙洞']
155121
xm1 = ['羽毛球', '游泳', '体能中心']
156122
xm2 = ['羽毛球', '健身中心', '游泳', '风雨篮球', '灯光篮球', '网球']
157123

158-
txt1 = Label(win, text="学号:")
159-
txt1.place(x=10, y=10)
160-
txt2 = Label(win, text="密码:")
161-
txt2.place(x=10, y=40)
162-
163-
text1 = Entry(win, width=14)
164-
text1.place(x=50, y=10)
165-
text2 = Entry(win, width=14, show="*")
166-
text2.place(x=50, y=40)
167-
168-
txt3 = Label(win, text="校区:")
169-
txt3.place(x=160, y=10)
170-
txt4 = Label(win, text="项目:")
171-
txt4.place(x=160, y=40)
172-
173-
box1 = ttk.Combobox(master=win, state="readonly", textvariable=value1, values=xq, width=8)
174-
box1.set(xq[0])
175-
box1.place(x=200, y=10)
176-
box2 = ttk.Combobox(master=win, state="readonly", textvariable=value2, values=xm1, width=8)
177-
box2.set(xm1[0])
178-
box2.place(x=200, y=40)
179-
box1.bind("<<ComboboxSelected>>", func)
180-
181-
txt5 = Label(win, text="日期:")
182-
txt5.place(x=10, y=70)
183-
txt6 = Label(win, text="开始时间:")
184-
txt6.place(x=10, y=100)
185-
txt7 = Label(win, text="结束时间:")
186-
txt7.place(x=10, y=130)
187-
txt8 = Label(win, text="预约时长:")
188-
txt8.place(x=10, y=160)
189-
190-
text3 = Entry(win, width=14)
191-
text3.insert(END, "格式:2019-08-18")
192-
text3.place(x=50, y=70)
193-
text3.bind("<Button-1>", lambda a: text3.delete(0, END))
124+
xh_text = Label(win, text="学号:")
125+
xh_text.place(x=10, y=10)
126+
mm_text = Label(win, text="密码:")
127+
mm_text.place(x=10, y=50)
128+
rq_text = Label(win, text="日期:")
129+
rq_text.place(x=10, y=90)
194130

195-
box3 = ttk.Combobox(master=win, state="readonly", values=[str(i) for i in range(9, 20)], width=7,
196-
textvariable=value3)
197-
box3.set('9')
198-
box3.place(x=80, y=100)
199-
box4 = ttk.Combobox(master=win, state="readonly", values=[str(i) for i in range(10, 21)], width=7,
200-
textvariable=value4)
201-
box4.set('10')
202-
box4.place(x=80, y=130)
203-
box5 = ttk.Combobox(master=win, state="readonly", values=[str(i) for i in range(1, 4)], width=7,
204-
textvariable=value5)
205-
box5.set('1')
206-
box5.place(x=80, y=160)
131+
xh_inp = Entry(win, width=11)
132+
xh_inp.place(x=50, y=10)
133+
mm_inp = Entry(win, width=11, show="*")
134+
mm_inp.place(x=50, y=50)
135+
rq_inp = Entry(win, width=11)
136+
rq_inp.place(x=50, y=90)
207137

208-
frame1 = Frame(win, width=130, height=85, highlightbackground="black", highlightthickness=1)
138+
kssj_text = Label(win, text="开始时间:")
139+
kssj_text.place(x=140, y=10)
140+
jssj_text = Label(win, text="结束时间:")
141+
jssj_text.place(x=140, y=50)
142+
yysc_text = Label(win, text="预约时长:")
143+
yysc_text.place(x=140, y=90)
209144

210-
self.r1_type = StringVar()
211-
self.r1_type.set('F')
212-
r1 = Checkbutton(frame1, text="定时提交预约", variable=self.r1_type, onvalue="T", offvalue="F")
213-
r1.place(x=15, y=0)
145+
kssj_inp = ttk.Combobox(master=win, state="readonly", values=[str(i) for i in range(9, 20)], width=7,
146+
textvariable=value3)
147+
kssj_inp.set('9')
148+
kssj_inp.place(x=205, y=10)
149+
jssj_inp = ttk.Combobox(master=win, state="readonly", values=[str(i) for i in range(10, 21)], width=7,
150+
textvariable=value4)
151+
jssj_inp.set('10')
152+
jssj_inp.place(x=205, y=50)
153+
yysc_inp = ttk.Combobox(master=win, state="readonly", values=[str(i) for i in range(1, 4)], width=7,
154+
textvariable=value5)
155+
yysc_inp.set('1')
156+
yysc_inp.place(x=205, y=90)
214157

215-
text4 = Entry(frame1, width=16)
216-
text4.insert(END, "日期:2021-12-06")
217-
text4.place(x=5, y=28)
218-
text4.bind("<Button-1>", lambda a: text4.delete(0, END))
158+
xq_test = Label(win, text="校区:")
159+
xq_test.place(x=285, y=10)
160+
xm_test = Label(win, text="项目:")
161+
xm_test.place(x=285, y=50)
219162

220-
box6 = ttk.Combobox(master=frame1, state="readonly", values=[str(i) for i in range(0, 23)], width=2)
221-
box6.set('0')
222-
box6.place(x=5, y=55)
223-
txt8 = Label(frame1, text="时")
224-
txt8.place(x=45, y=55)
225-
box7 = ttk.Combobox(master=frame1, state="readonly", values=[str(i) for i in range(0, 60)], width=2)
226-
box7.set('0')
227-
box7.place(x=65, y=55)
228-
txt9 = Label(frame1, text="分")
229-
txt9.place(x=105, y=55)
163+
xq_inp = ttk.Combobox(master=win, state="readonly", textvariable=value1, values=xq, width=8)
164+
xq_inp.set(xq[0])
165+
xq_inp.place(x=325, y=10)
166+
xm_inp = ttk.Combobox(master=win, state="readonly", textvariable=value2, values=xm1, width=8)
167+
xm_inp.set(xm1[0])
168+
xm_inp.place(x=325, y=50)
169+
xq_inp.bind("<<ComboboxSelected>>", func)
230170

231-
frame1.place(x=160, y=68)
171+
yy_btn = Button(win, text="预约", command=main_run, width=14)
172+
yy_btn.place(x=292, y=85)
232173

233-
btn = Button(win, text="预约", command=main_run, width=14)
234-
btn.place(x=170, y=158)
174+
print('请输入信息以预约')
175+
print('!!!请注意日期格式为\"2022-11-29\"!!!')
235176

236177
win.mainloop()
237178

@@ -291,7 +232,7 @@ def random_string(length):
291232
self.token = loads(opener.open(result).read().decode('utf-8'))['data']['infa']['openid']
292233
print('登录成功')
293234

294-
def main(self):
235+
def send_info(self):
295236
# 生成时间列表
296237
timelst = []
297238
if self.starttime < self.endtime:
@@ -369,5 +310,6 @@ def main(self):
369310

370311

371312
if __name__ == '__main__':
372-
run = Ydsz()
313+
main = Ydsz()
314+
main.run()
373315
input('程序结束,按回车键退出')

0 commit comments

Comments
 (0)