1010import shutil
1111import time
1212
13- from rich .console import Console
13+ from rich .console import Console , Group
14+ from rich .panel import Panel
1415from rich .table import Table
16+ from rich .text import Text
1517
1618from my_xxt .findAnswer import match_answer
1719from my_xxt .api import NewXxt
@@ -278,20 +280,27 @@ def find_work(works: list, work_id: str) -> dict:
278280
279281
280282def show_start (console : Console ) -> None :
281- console .rule ("欢迎使用该做题脚本" )
282- console .print (" ███╗ ██╗███████╗██╗ ██╗ ██╗ ██╗██╗ ██╗████████╗\n \
283+
284+ console .print (Panel (
285+ title = "[white]欢迎使用该做题脚本" ,
286+ renderable =
287+ Group (
288+ Text (" ███╗ ██╗███████╗██╗ ██╗ ██╗ ██╗██╗ ██╗████████╗\n \
283289 ████╗ ██║██╔════╝██║ ██║ ╚██╗██╔╝╚██╗██╔╝╚══██╔══╝\n \
284290 ██╔██╗ ██║█████╗ ██║ █╗ ██║ ╚███╔╝ ╚███╔╝ ██║\n \
285291 ██║╚██╗██║██╔══╝ ██║███╗██║ ██╔██╗ ██╔██╗ ██║\n \
286292 ██║ ╚████║███████╗╚███╔███╔╝███████╗██╔╝ ██╗██╔╝ ██╗ ██║\n \
287- ╚═╝ ╚═══╝╚══════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ " , justify = "center" )
288-
289- console .print ("[red]注意:该脚本仅供学习参考,详细信息请参考https://github.com/aglorice/new_xxt" )
290- console .print (f"[red]当前版本为 { __VERSION__ } " )
293+ ╚═╝ ╚═══╝╚══════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ " , justify = "center" ,style = "bold white" ),
294+ Text ("注意:该脚本仅供学习参考,详细信息请参考https://github.com/aglorice/new_xxt" , justify = "center" , style = "bold red" ),
295+ Text (f"当前版本为 { __VERSION__ } " , justify = "center" , style = "bold red" ),
296+ ),
297+ style = "bold green" ,
298+ width = 120 ,
299+ ))
291300
292301
293302def show_users (users : dict , console : Console ) -> None :
294- tb = Table ("序号" , "账号" , "密码" , "姓名" , border_style = "blue" )
303+ tb = Table ("序号" , "账号" , "密码" , "姓名" , border_style = "blue" , width = 116 )
295304 i = 0
296305
297306 for user in users ["users" ]:
@@ -302,20 +311,32 @@ def show_users(users: dict, console: Console) -> None:
302311 user ["name" ],
303312 )
304313 i = i + 1
305- console .rule ("[blue]用户表" , characters = "*" )
306- console .print (tb )
314+
315+ console .print (
316+ Panel (
317+ title = "[blue]用户表" ,
318+ renderable = tb ,
319+ style = "bold green" ,
320+ )
321+ )
307322
308323
309324def show_course (courses : list , console : Console ) -> None :
310- tb = Table ("序号" , "课程名" , "老师名" , border_style = "blue" )
325+ tb = Table ("序号" , "课程名" , "老师名" , border_style = "blue" , width = 116 )
311326 for course in courses :
312327 tb .add_row (
313328 f"[green]{ course ['id' ]} " ,
314329 course ["course_name" ],
315330 course ["course_teacher" ],
331+ style = "bold yellow"
332+ )
333+ console .print (
334+ Panel (
335+ title = "[blue]课程信息" ,
336+ renderable = tb ,
337+ style = "bold green" ,
316338 )
317- console .rule ("[blue]课程信息" , characters = "*" )
318- console .print (tb )
339+ )
319340
320341
321342def select_users (users : dict , console : Console ) -> list :
@@ -334,44 +355,62 @@ def select_users(users: dict, console: Console) -> list:
334355
335356
336357def show_menu (console : Console ) -> None :
337- console .rule ("[green]菜单" , characters = "+" )
338- console .print ("1.查看课程" , highlight = True )
339- console .print ("2.查看当前所有答案文件" , highlight = True )
340- console .print ("3.查询所有未完成的作业" , highlight = True )
341- console .print ("4.清除所有答案文件" , highlight = True )
342- console .print ("5.爬取指定作业的答案" , highlight = True )
343- console .print ("6.批量爬取指定课程的答案" , highlight = True )
344- console .print ("7.完成作业(请先确认是否已经爬取了你想要完成作业的答案)" , highlight = True )
345- console .print ("8.批量完成作业完成作业(请先确认是否已经爬取了你想要完成作业的答案,请填好user.json里的账号数据)" ,
346- highlight = True )
347- console .print ("9.退出登录" , highlight = True )
348- console .rule (characters = "+" )
358+ console .print (Panel (
359+ title = "[green]菜单" ,
360+ renderable =
361+ Group (
362+ Text ("1.查看课程" , justify = "center" , style = "bold yellow" ),
363+ Text ("2.查看当前所有答案文件" , justify = "center" , style = "bold yellow" ),
364+ Text ("3.查询所有未完成的作业" , justify = "center" , style = "bold yellow" ),
365+ Text ("4.清除所有答案文件" , justify = "center" , style = "bold yellow" ),
366+ Text ("5.爬取指定作业的答案" , justify = "center" , style = "bold yellow" ),
367+ Text ("6.批量爬取指定课程的答案" , justify = "center" , style = "bold yellow" ),
368+ Text ("7.完成作业(请先确认是否已经爬取了你想要完成作业的答案)" , justify = "center" , style = "bold yellow" ),
369+ Text ("8.批量完成作业完成作业(请先确认是否已经爬取了你想要完成作业的答案,请填好user.json里的账号数据)" ,
370+ justify = "center" , style = "bold yellow" ),
371+ Text ("9.退出登录" , justify = "center" , style = "bold yellow" ),
372+ ),
373+ style = "bold green" ,
374+ width = 120 ,
375+ ))
349376
350377
351378def show_works (works : list , console : Console ) -> None :
352- tb = Table ("id" , "作业名称" , "作业状态" , "分数" , "是否可以重做" , border_style = "blue" )
379+ tb = Table ("id" , "作业名称" , "作业状态" , "分数" , "是否可以重做" , border_style = "blue" , width = 116 )
353380 for work in works :
354381 tb .add_row (
355382 f"[green]{ work ['work_id' ]} " ,
356383 work ['work_name' ],
357384 work ["work_status" ],
358385 work ["score" ],
359- work ["isRedo" ]
386+ work ["isRedo" ],
387+ style = "bold yellow"
360388 )
361- console .rule ("[blue]作业信息" , characters = "*" )
362- console .print (tb )
389+ console .print (
390+ Panel (
391+ title = "[blue]作业信息" ,
392+ renderable = tb ,
393+ style = "bold green" ,
394+ )
395+ )
363396
364397
365398def show_answer (console : Console , answer_list : list ) -> None :
366- tb = Table ("id" , "题目名称" , "答案" , border_style = "blue" )
399+ tb = Table ("id" , "题目名称" , "答案" , border_style = "blue" , width = 116 )
367400 for answer in answer_list :
368401 tb .add_row (
369402 f"[green]{ answer ['id' ]} " ,
370403 answer ['title' ],
371- str (answer ["answer" ])
404+ str (answer ["answer" ]),
405+ style = "bold yellow"
406+ )
407+ console .print (
408+ Panel (
409+ title = "[blue]检查答案" ,
410+ renderable = tb ,
411+ style = "bold green" ,
372412 )
373- console .rule ("[blue]检查答案" , characters = "*" )
374- console .print (tb )
413+ )
375414
376415
377416def dateToJsonFile (answer : list , info : dict ) -> None :
@@ -410,16 +449,22 @@ def show_all_answer_file(console: Console) -> None:
410449 _path = os .path .join (path , item )
411450 answer_file_info .append (jsonFileToDate (_path )["info" ])
412451
413- tb = Table ("id" , "作业名" , "文件名称" , "课程名称" , border_style = "blue" )
452+ tb = Table ("id" , "作业名" , "文件名称" , "课程名称" , border_style = "blue" , width = 116 )
414453 for work_info in answer_file_info :
415454 tb .add_row (
416455 f"[green]{ work_info ['id' ]} " ,
417456 work_info ["work_name" ],
418457 work_info ["id" ] + ".json" ,
419458 work_info ["course_name" ],
459+ style = "bold yellow"
460+ )
461+ console .print (
462+ Panel (
463+ title = "[blue]作业文件列表" ,
464+ renderable = tb ,
465+ style = "bold green" ,
420466 )
421- console .rule ("[blue]作业文件列表" , characters = "*" )
422- console .print (tb )
467+ )
423468
424469
425470def is_exist_answer_file (work_file_name : str ) -> bool :
@@ -464,13 +509,20 @@ def get_not_work(courses: list, xxt: NewXxt, console: Console, sleep_time: float
464509
465510
466511def show_not_work (not_work : list , console : Console ) -> None :
467- tb = Table ("id" , "作业名" , "课程名称" , "作业状态" , border_style = "blue" )
512+ tb = Table ("id" , "作业名" , "课程名称" , "作业状态" , border_style = "blue" , width = 116 )
468513 for work in not_work :
469514 tb .add_row (
470515 f"[green]{ work ['id' ]} " ,
471516 work ["work_name" ],
472517 work ["course_name" ],
473518 f"[green]{ work ['work_status' ]} " ,
519+ style = "bold yellow"
520+ )
521+
522+ console .print (
523+ Panel (
524+ title = "[blue]作业文件列表" ,
525+ renderable = tb ,
526+ style = "bold green" ,
474527 )
475- console .rule ("[blue]作业文件列表" , characters = "*" )
476- console .print (tb )
528+ )
0 commit comments