-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.py
More file actions
119 lines (106 loc) · 4.39 KB
/
Copy pathcontrol.py
File metadata and controls
119 lines (106 loc) · 4.39 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
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
import subprocess
from pathlib import Path
import threading
import logging
class Controller:
# 导入UI类后,替换以下的 object 类型,将获得 IDE 属性提示功能
ui: object
def __init__(self):
self.win = None
def init(self, ui):
"""
得到UI实例,对组件进行初始化配置
"""
self.ui = ui
# TODO 组件初始化 赋值操作
logging.basicConfig(
filename='app.log', # 日志文件名
level=logging.INFO, # 日志级别
format='%(asctime)s - %(levelname)s - [GUI] %(message)s', # 日志格式
datefmt='%Y-%m-%d %H:%M:%S',
encoding='utf-8'
)
#控制台日志输出
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - [control] %(message)s')
console_handler.setFormatter(formatter)
logging.getLogger().addHandler(console_handler)
def start_main(self,evt):
input_url = self.ui.get_input_url()
selected_platform = self.ui.get_selected_platform()
show_result = self.ui.get_show_result_checkbox_state()
if input_url and selected_platform == "bili":
logging.info(f"开始处理B站URL: {input_url}")
cmd = [
'python',
'main.py',
'--platform', 'bili',
'--url', str(input_url),
*(['--show'] if show_result else [])
]
threading.Thread(target=subprocess.run, args=(cmd,), kwargs={'creationflags': subprocess.CREATE_NO_WINDOW}).start()
elif input_url and selected_platform == "xhs":
logging.info(f"开始处理小红书URL: {input_url}")
cmd = [
'python',
'main.py',
'--platform', 'xhs',
'--url', str(input_url),
*(['--show'] if show_result else [])
]
threading.Thread(target=subprocess.run, args=(cmd,), kwargs={'creationflags': subprocess.CREATE_NO_WINDOW}).start()
elif input_url and selected_platform == "wb":
logging.info(f"开始处理微博URL: {input_url}")
cmd = [
'python',
'main.py',
'--platform', 'wb',
'--url', str(input_url),
*(['--show'] if show_result else [])
]
threading.Thread(target=subprocess.run, args=(cmd,), kwargs={'creationflags': subprocess.CREATE_NO_WINDOW}).start()
elif not input_url :
logging.warning("未输入URL")
elif not selected_platform:
logging.warning("未选择平台")
#elif 'http' not in input_url:
# print('请输入有效的URL')
def init_trie(self,evt):
logging.info("开始构建Trie树")
from main import trie_prebuild
trie_prebuild()
logging.info("Trie树构建完成")
def browser_login_bilibili(self,evt):
logging.info("开始B站登录")
current_dir = Path(__file__).parent.absolute()
crawler_dir = current_dir / "MediaCrawler-Modified"
cmd = [
'python',
'main.py',
'--platform', 'bili',
'--lt', 'qrcode'
]
threading.Thread(target=subprocess.run, args=(cmd,), kwargs={'cwd': str(crawler_dir), 'creationflags': subprocess.CREATE_NO_WINDOW}).start()
def browser_login_xhs(self,evt):
logging.info("开始小红书登录")
current_dir = Path(__file__).parent.absolute()
crawler_dir = current_dir / "MediaCrawler-Modified"
cmd = [
'python',
'main.py',
'--platform', 'xhs',
'--lt', 'qrcode'
]
threading.Thread(target=subprocess.run, args=(cmd,), kwargs={'cwd': str(crawler_dir), 'creationflags': subprocess.CREATE_NO_WINDOW}).start()
def browser_login_wb(self,evt):
logging.info("开始微博登录")
current_dir = Path(__file__).parent.absolute()
crawler_dir = current_dir / "MediaCrawler-Modified"
cmd = [
'python',
'main.py',
'--platform', 'wb',
'--lt', 'qrcode'
]
threading.Thread(target=subprocess.run, args=(cmd,), kwargs={'cwd': str(crawler_dir), 'creationflags': subprocess.CREATE_NO_WINDOW}).start()