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 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
| import time import tkinter.messagebox as messagebox import tkinter as tk import random import winsound import requests from PIL import Image, ImageTk import threading import os from lxml import etree
headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0', } cookies = {} urp_url = '1' thread_class_flag = True class_inf = '2' class LoginWindow: def __init__(self): self.window = tk.Tk() self.window.title("登录") self.window.geometry("300x200") self.window.resizable(0,0) self.window.iconbitmap('ic.ico') start_url = set_urp_url() self.username_label = tk.Label(self.window, text="当前登录网址:" + urp_url) self.username_label.place(x=30, y=0) self.username_label = tk.Label(self.window, text="用户名:") self.username_label.place(x=50, y=30) self.username_entry = tk.Entry(self.window, width=20) self.username_entry.place(x=110, y=30)
self.password_label = tk.Label(self.window, text="密码:") self.password_label.place(x=50, y=70) self.password_entry = tk.Entry(self.window, width=20) self.password_entry.place(x=110, y=70)
self.verify_label = tk.Label(self.window, text="验证码:") self.verify_label.place(x=50, y=110) self.verify_entry = tk.Entry(self.window, width=10) self.verify_entry.place(x=110, y=110)
def on_enter(event): event.widget.tk_focusNext().focus() def on_enter_code(event): self.login() self.username_entry.bind("<Return>",on_enter) self.password_entry.bind("<Return>",on_enter) self.verify_entry.bind("<Return>",on_enter_code) def refresh_code(): start_url.getcode() self.verify_image = Image.open("code.png") self.verify_image = ImageTk.PhotoImage(self.verify_image) self.verify_button.config(image=self.verify_image) start_url.getcode() self.verify_image = Image.open("code.png") self.verify_image = ImageTk.PhotoImage(self.verify_image) self.verify_button = tk.Button(self.window, command=refresh_code) self.verify_button.config(image=self.verify_image) self.verify_button.place(x=190, y=110)
self.login_button = tk.Button(self.window, width=10, text="登录", command=self.login) self.login_button.place(x=120, y=150)
try: with open("user.txt", "r") as file: lines = file.readlines() if len(lines) >= 1: self.username_entry.insert(0, lines[0].strip()) if len(lines) >= 2: self.password_entry.insert(0, lines[1].strip()) except FileNotFoundError: print("找不到user.txt文件") self.window.mainloop()
def login(self): url = urp_url + '/loginAction.do' print(url) while True: data = { 'zjh1': '', 'tips': '', 'lx': '', 'evalue': '', 'eflag': '', 'fs': '', 'dzslh': '', 'zjh': self.username_entry.get(), 'mm': self.password_entry.get(), 'v_yzm': self.verify_entry.get(), }
print("用户名:", data["zjh"]) print("密码:", data['mm']) print("验证码:", data['v_yzm']) try: response = requests.session().post(url=url, headers=headers, cookies=cookies, data=data, timeout=90).text tree = etree.HTML(response) login_staut = tree.xpath('//head/title/text()')[0] print(login_staut) if login_staut != '学分制综合教务': login_staut = tree.xpath('//td[@class="errorTop"]/strong/font/text()')[0] print(login_staut) messagebox.showinfo('错误',login_staut) raise Exception break except: return while True: try: requests.get(urp_url + '/xkAction.do', headers=headers, cookies=cookies, timeout=90) break except: return self.window.destroy()
with open("user.txt", "w") as file: file.write(data['zjh'] + "\n") file.write(data['mm'] + "\n") print("已将文本写入user.txt文件。") menu(data['zjh'])
class menu: def __init__(self,user): root = tk.Tk() root.title("当前用户:"+user) root.geometry("400x300") root.resizable(0, 0) root.iconbitmap('ic.ico') lbl_title = tk.Label(root, text="urp TOOL", font=("Arial", 20)) lbl_title.pack(pady=10)
def class_table(): url = urp_url + '/xkAction.do?actionType=6' response = requests.get(url, headers=headers, cookies=cookies) with open("cx.html", 'wb') as fp: fp.write(response.content) os.system('cx.html') btn_query = tk.Button(root, text="查询课表", width=15, height=2,command=class_table) btn_query.pack(pady=5)
def select_class(): root.withdraw() class_window = tk.Toplevel(root) class_window.title("选课:"+user) class_window.geometry("355x460") class_window.resizable(0, 0) class_window.iconbitmap("ic.ico") def closing(): root.deiconify() class_window.destroy() class_window.protocol('WM_DELETE_WINDOW',closing) label1 = tk.Label(class_window,text = "课程号") label1.grid(row=0,column=0) entry1 = tk.Entry(class_window) entry1.grid(row=0,column=1) label1 = tk.Label(class_window, text="课序号") label1.grid(row=1, column=0) entry2 = tk.Entry(class_window) entry2.grid(row=1, column=1) def add_class(): input1 = entry1.get() input2 = entry2.get() if not (input1 == '' and input2==''): classbox.insert(tk.END, f"{input1},{input2}") def delete_selected_class(): selected_class = classbox.curselection() if selected_class: classbox.delete(selected_class) button1 = tk.Button(class_window,text='添加课程',command=add_class) button1.grid(row=0,column=2) button2 = tk.Button(class_window, text='删除课程', command=delete_selected_class) button2.grid(row=1, column=2) classbox = tk.Listbox(class_window,width=50, height=5) classbox.grid(row=2,column=0,columnspan=3) try: for line in open('kc.txt', 'r'): line = line.rstrip('\n').split(" ") classbox.insert(tk.END,f"{line[0]},{line[1]}") except: messagebox.showinfo("WARING","检测到缺少课程文件,可手动添加课程") class_window.quit()
def selectthread(): len_class = classbox.size() i = 0 global thread_class_flag while len_class !=0 and thread_class_flag: i = i % len_class kcid = classbox.get(i).split(',')[0] kcnum = classbox.get(i).split(',')[1] print(kcid,kcnum) url = urp_url + '/xkAction.do' da = {} if class_inf == '5': da = { 'kch': kcid, 'cxkxh': kcnum, 'kcm': "", 'skjs': "", 'kkxsjc': "", 'skxq': "", 'skjc': "", 'pageNumber': "-2", 'preActionType': "3", 'actionType': "5", } elif class_inf == '2': da = { "jhxn": "", "kcsxdm": "", "kch": kcid, "cxkxh": kcnum, "actionType": "2", "oper2": "gl", "pageNumber": "-1" } while True: try: st = time.time() re = requests.post(urp_url + '/xkAction.do', headers=headers, cookies=cookies, data=da, timeout=90) cost_time = time.time()-st urp_label.config(text=urp_url+" "+f"延时: {cost_time:.3f} 秒",fg="blue") break except: return
data = { 'kcId': kcid + '_' + kcnum, 'preActionType': class_inf, 'actionType': '9', } while True: try: st = time.time() response = requests.post(url, headers=headers, cookies=cookies, data=data, timeout=90).text cost_time = time.time() - st urp_label.config(text=urp_url + " " + f"延时: {cost_time:.3f} 秒", fg="blue") break except: return
try: tree = etree.HTML(response) ret = tree.xpath('//strong/font/text()') status_box.insert(tk.END, str(i+1)+":"+ret[0]) status_box.yview_moveto(1.0) class_window.update() if "时间冲突" in ret[0] or "成功" in ret[0] or "已经选择" in ret[0]: print(ret[0]) classbox.delete(i) len_class -= 1 if "成功" in ret[0]: try: winsound.PlaySound("succeed.wav", winsound.SND_ASYNC) except: print("找不到音频")
except: print("暂无课程信息,请稍后重试") status_box.insert(tk.END, str(i+1)+":"+"暂无课程信息,请稍后重试") status_box.yview_moveto(1.0) class_window.update() i += 1 if delay_slider.get()!=0: delay_time = delay_slider.get()+random.uniform(0, 2)-random.uniform(0,1.5) delay_time = max(0,delay_time) print("延迟:",round(delay_time,2),"s") status_box.insert(tk.END, "延迟:"+str(delay_time)+"s") status_box.yview_moveto(1.0) class_window.update() time.sleep(delay_time)
if len_class==0: button4.config(text="开始选课") urp_label.config(text=urp_url, fg='black') status_box.insert(tk.END,"************选课任务完成************") if not thread_class_flag: status_box.insert(tk.END, "选课已暂停,等待服务器响应...") status_box.see(tk.END) button4.config(state=tk.NORMAL) urp_label.config(text=urp_url,fg='black')
def Thread_class(): global thread_class_flag thread = threading.Thread(target=selectthread) if button4.cget("text") == "开始选课": thread_class_flag = True status_box.insert(tk.END,"开始选课,等待服务器响应...") status_box.see(tk.END) button4.config(text="暂停选课") thread.start() else: button4.config(text="开始选课",state=tk.DISABLED) thread_class_flag = False
button4 = tk.Button(class_window, width=12,text='开始选课',command=Thread_class) button4.grid(row=4, column=1, columnspan=2)
delay_slider = tk.Scale(class_window, from_=0.0, to=5.0, resolution=0.01, orient="horizontal", length=200) delay_slider.grid(row=5,column=0,columnspan=3) def change_class(): global class_inf if class_inf == '2': class_inf = '5' class_label.config(text='课程属性:自由选择') elif class_inf == '5': class_inf='2' class_label.config(text='课程属性:方案课程') button5 = tk.Button(class_window, width=10, text='切换属性', command=change_class) button5.grid(row=4, column=0, columnspan=2)
status_box = tk.Listbox(class_window, width=50) status_box.grid(row=3, column=0, columnspan=3)
class_label = tk.Label(class_window, text="课程属性:方案课程" ) class_label.grid(row=6, column=1) urp_label = tk.Label(class_window, text=urp_url) urp_label.grid(row=7,column=0,columnspan=3)
btn_quick_select = tk.Button(root, text="快速选课", width=15, height=2,command=select_class) btn_quick_select.pack(pady=5)
def jxpg(): print("\n正在读取教学评估界面\n") resp = requests.get(url=urp_url + "/jxpgXsAction.do?oper=listWj", headers=headers, cookies=cookies) tree = etree.HTML(resp.text) list = tree.xpath('//body/form/table/tr/td/table/tr/td/img[@title="评估"]/@name') if len(list)==0: messagebox.showinfo("提醒","当前可评估数目为0,正在返回菜单") else: new_window = tk.Toplevel(root) new_window.title("评教") new_window.geometry("400x500") new_window.resizable(0, 0) risk_box = tk.Listbox(new_window, width=50) risk_box.pack() status_box = tk.Listbox(new_window, width=50) status_box.pack() for i in list: j=i.split("#@") risk_box.insert(tk.END,"教师姓名:"+j[2]+" 课程名:"+j[4]) print("共 ", len(list), " 个评估任务") risk_count = tk.Label(new_window, text="共 "+ str(len(list))+ " 个评估任务") risk_count.pack(pady=10)
def start_jxpg(): for item in list: info = item.split('#@') print(info) data_flag = { 'wjbm': info[0], 'bpr': info[1], 'pgnr': info[5], 'oper': 'wjShow', "wjbz": "null", "pageSize": "20", "page": "1", "currentPage": "1", "pageNo": "", } data = { "wjbm": info[0], "bpr": info[1], "pgnr": info[5], "xumanyzg": 'zg', "wjbz": "", "0000000257": "40_0.96", "0000000258": "12_0.96", "0000000259": "10_0.96", "0000000260": "8_0.96", "0000000261": "8_0.96", "0000000262": "5_0.96", "0000000263": "5_0.96", "0000000264": "4_0.96", "0000000265": "4_0.96", "0000000266": "4_0.96", "0000000271": "0_0.96", "0000000272": "0_0.2", "0000000273": "0_0.96", "zgpj": "好" } requests.post(urp_url + '/jxpgXsAction.do', cookies=cookies, data=data_flag) res = requests.post(url=urp_url + "/jxpgXsAction.do?oper=wjpg", cookies=cookies, data=data) tree = etree.HTML(res.text) status = tree.xpath('//script/text()')[0].split('"')[1] status_box.insert(tk.END,status) btn_query = tk.Button(new_window, text="开始评估", width=15, height=2, command=start_jxpg) btn_query.pack(pady=5) btn_eval = tk.Button(root, text="一键评教", width=15, height=2,command=jxpg) btn_eval.pack(pady=5)
def cancel_class(): root.withdraw() cancle_window = tk.Toplevel(root) cancle_window.title("退课") cancle_window.geometry("355x260") cancle_window.resizable(0, 0) cancle_window.iconbitmap("ic.ico") def closing(): root.deiconify() cancle_window.destroy() cancle_window.protocol('WM_DELETE_WINDOW', closing) lable1 = tk.Label(cancle_window,text="请选择所需退课课程") lable1.grid(row=0,column=1,columnspan=3) cancle_box = tk.Listbox(cancle_window,width=50,height=10) cancle_box.grid(row=1,column=1,columnspan=3) def class_input_thread(): cancle_response = requests.get(url=urp_url+"/xkAction.do?actionType=6",cookies=cookies,headers=headers) tree = etree.HTML(cancle_response.text) cancle_list = tree.xpath('//table/tr[count(td) > 15]/td[position()=2 or position()=3 or position()=4 or position()=8]/text()') for row in range(0,len(cancle_list),4): cancle_box.insert(tk.END,cancle_list[row][4:]+","+cancle_list[row+1][4:]+","+cancle_list[row+2][4:]+","+cancle_list[row+3][4:]) def thread_class(): thread = threading.Thread(target=class_input_thread) thread.start() def ACK_cancle(): select_box_index = cancle_box.curselection() if select_box_index: ACK_class = cancle_box.get(select_box_index[0]).split(',') requests.get(url=urp_url+"/xkAction.do?actionType=10&kcId="+ACK_class[0],cookies=cookies,headers=headers) messagebox.showinfo("完成",message="请按确认校验退课结果") cancle_box.delete(0,"end") thread_class() else: messagebox.showwarning("警告","请先选定课程") thread_class() cancle_button = tk.Button(cancle_window,text="确认退课",command=ACK_cancle) cancle_button.grid(row=2,column=1,columnspan=3) btn_drop = tk.Button(root, text="退课", width=15, height=2,command=cancel_class) btn_drop.pack(pady=5)
root.mainloop()
class set_urp_url: urp_url_list = ["http://10.28.63.116:8081", "http://10.28.63.111:9001", "http://10.28.63.111:9002", ] URL_flag = True
def __init__(self): url_count = len(self.urp_url_list)
def xzURLthread(i): try: response = requests.get(self.urp_url_list[int(i)], timeout=90) except: return if not self.URL_flag: return global urp_url global cookies urp_url = self.urp_url_list[int(i)] cookies = response.cookies.get_dict() self.URL_flag = False
lock_url.set()
threads = [] lock_url = threading.Event() for i in range(0, url_count): t = threading.Thread(target=xzURLthread, args=[i]) threads.append(t) for thread in threads: thread.start() lock_url.wait() print(urp_url)
def getcode(self): code_url = urp_url + '/validateCodeAction.do?random=0.5925328096959378' mysession = requests.session() response = mysession.get(code_url, headers=headers, cookies=cookies) content = response.content with open('code.png', 'wb') as fp: fp.write(content)
if __name__=='__main__': try: LoginWindow() except: messagebox.showinfo('Error','发生了未知错误,请检测网络是否连接')
|