Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 117e2b5

Browse files
committed
feat: 优化ui显示
1 parent 6f64f77 commit 117e2b5

File tree

3 files changed

+120
-55
lines changed

3 files changed

+120
-55
lines changed

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from my_xxt.login import login
55

66
# 设置控制台的宽度
7-
console = Console(width=100)
7+
console = Console(width=120)
88

99
if __name__ == '__main__':
1010
while True:

my_xxt/login.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import time
99

1010
from qrcode import QRCode
11-
from rich.console import Console
11+
from rich.console import Console, Group
12+
from rich.panel import Panel
1213
from rich.table import Table
14+
from rich.text import Text
1315

1416
from my_xxt.api import NewXxt
1517
from my_xxt.my_tools import select_error, jsonFileToDate
@@ -30,7 +32,7 @@ def login(console: Console, xxt: NewXxt) -> None:
3032
dir_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
3133
path = os.path.join(dir_path, "user.json")
3234
ret = jsonFileToDate(path)
33-
user = select_users(ret,console)
35+
user = select_users(ret, console)
3436
login_status = xxt.login(user["phone"], user["password"])
3537
if not login_status["status"]:
3638
flag = console.input("[green]登录失败,请重新尝试!(按q退出,按任意键继续):")
@@ -45,11 +47,17 @@ def login(console: Console, xxt: NewXxt) -> None:
4547

4648

4749
def select_login(console: Console):
48-
console.rule("登录方式")
49-
console.print("1.手机号密码登录", highlight=True, justify="center")
50-
console.print("2.扫码登录", highlight=True, justify="center")
51-
console.print("3.查看当前所有账号(选择其中的一个登录)", highlight=True, justify="center")
52-
console.rule("")
50+
console.print(Panel(
51+
title="[green]登陆方式",
52+
renderable=
53+
Group(
54+
Text("1.手机号密码登录", justify="center", style="bold blue"),
55+
Text("2.扫码登录", justify="center", style="bold blue"),
56+
Text("3.查看当前所有账号(选择其中的一个登录)", justify="center", style="bold blue"),
57+
),
58+
style="bold green",
59+
width=120,
60+
))
5361
choose = console.input("请选择你要登录的方式:")
5462
return choose
5563

@@ -98,23 +106,28 @@ def qr_login(console: Console, xxt: NewXxt):
98106
time.sleep(1.0)
99107

100108

101-
def select_users(users: dict,console:Console):
102-
tb = Table("序号", "账号", "密码","姓名", border_style="blue")
109+
def select_users(users: dict, console: Console):
110+
tb = Table("序号", "账号", "密码", "姓名", border_style="blue",width=116)
103111
i = 0
104112
for user in users["users"]:
105113
tb.add_row(
106-
f"[green]{i+1}",
114+
f"[green]{i + 1}",
107115
user["phone"],
108116
user["password"],
109117
user["name"],
118+
style="bold yellow"
110119
)
111-
i = i+1
112-
console.rule("[blue]用户表", characters="*")
113-
console.print(tb)
120+
i = i + 1
121+
console.print(
122+
Panel(
123+
title="[green]用户表",
124+
renderable=tb,
125+
style="bold green",
126+
)
127+
)
114128
while True:
115129
user_id = int(console.input("[yellow]请选择你要登录的账号:"))
116130
try:
117-
return users["users"][user_id-1]
131+
return users["users"][user_id - 1]
118132
except Exception as e:
119133
select_error(console)
120-

my_xxt/my_tools.py

Lines changed: 91 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import shutil
1111
import time
1212

13-
from rich.console import Console
13+
from rich.console import Console, Group
14+
from rich.panel import Panel
1415
from rich.table import Table
16+
from rich.text import Text
1517

1618
from my_xxt.findAnswer import match_answer
1719
from my_xxt.api import NewXxt
@@ -278,20 +280,27 @@ def find_work(works: list, work_id: str) -> dict:
278280

279281

280282
def 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

293302
def 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

309324
def 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

321342
def select_users(users: dict, console: Console) -> list:
@@ -334,44 +355,62 @@ def select_users(users: dict, console: Console) -> list:
334355

335356

336357
def 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

351378
def 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

365398
def 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

377416
def 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

425470
def 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

466511
def 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

Comments
 (0)