This repository was archived by the owner on Jun 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (39 loc) · 1.56 KB
/
main.py
File metadata and controls
52 lines (39 loc) · 1.56 KB
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
from rich.console import Console
from rich.traceback import install
from my_xxt.my_tools import select_menu, show_start
from my_xxt.api import NewXxt
from my_xxt.login import login
from config import __LOG_FILE__, __SCREEN_WIDTH__
class MyConsole(Console):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.log_file = open(__LOG_FILE__, "w", encoding="utf-8")
def log(self, *args, **kwargs):
super().log(*args, **kwargs)
if not self.log_file.closed:
self.log_file.write("\n"+" ".join(map(str, args)) + "\n")
def print(self, *args, **kwargs):
super().print(*args, **kwargs)
captured_output_value = super().export_text()
if not self.log_file.closed:
self.log_file.write("\n"+captured_output_value+"\n")
def cleanup(self):
if not self.log_file.closed:
self.log_file.close()
def __del__(self):
self.cleanup()
def main():
console = MyConsole(width=__SCREEN_WIDTH__, record=True)
install(console=console, show_locals=True, width=__SCREEN_WIDTH__)
try:
while True:
show_start(console)
new_xxt_instance = NewXxt()
login(console, new_xxt_instance)
select_menu(console, new_xxt_instance)
except Exception as e:
console.log(f"程序退出: {e}", style="bold red")
console.log_exception(e)
console.log("如果需要反馈错误信息,请将对应的日志文件以及问题反映给作者", style="bold red")
if __name__ == '__main__':
main()