优化导包顺序,修复颜色显示不正常的问题
This commit is contained in:
parent
78996e841c
commit
ec44c11024
@ -1,10 +1,6 @@
|
||||
import re
|
||||
|
||||
|
||||
def extract_urls(text):
|
||||
return re.findall(r'https?://\S+', text)
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
try:
|
||||
with open(filename, 'r') as file:
|
||||
@ -29,54 +25,79 @@ def replace_urls(js_content, url_mapping):
|
||||
return js_content
|
||||
|
||||
|
||||
def get_hth_url_mapping(urls, is_seo):
|
||||
if is_seo:
|
||||
return {
|
||||
"{{hthApp}}": urls[4],
|
||||
"{{hthtyApp}}": urls[5],
|
||||
"{{hthPc}}": urls[0],
|
||||
"{{hthH5}}": urls[1]
|
||||
def get_url_mapping(urls_with_context, is_seo, template_type):
|
||||
categories = {}
|
||||
|
||||
# 初始化categories字典,区分SEO和非SEO模式
|
||||
if is_seo or template_type == 'ky':
|
||||
categories = {"WEB": [], "H5": [], "全站": [], "体育": []}
|
||||
else: # 非SEO模式下的hth模板
|
||||
categories = {"web": [], "h5": [], "全站APP": [], "体育APP": []}
|
||||
|
||||
# 遍历URLs及其前文本的元组列表进行分类
|
||||
for context, url in urls_with_context:
|
||||
key = context.strip().replace(" ", "")
|
||||
if key in categories:
|
||||
categories[key].append(url)
|
||||
|
||||
# 构建映射字典,直接返回结果
|
||||
if template_type == 'hth':
|
||||
url_mapping = {
|
||||
"{{hthApp}}": categories.get("全站", [""])[0] if is_seo else categories.get("全站APP", [""])[0],
|
||||
"{{hthtyApp}}": categories.get("体育", [""])[0] if is_seo else categories.get("体育APP", [""])[0],
|
||||
"{{hthPc}}": categories.get("WEB", [""])[0] if is_seo else categories.get("web", [""])[0],
|
||||
"{{hthH5}}": categories.get("H5", [""])[0] if is_seo else categories.get("h5", [""])[0]
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"{{hthApp}}": urls[2],
|
||||
"{{hthtyApp}}": urls[3],
|
||||
"{{hthPc}}": urls[0],
|
||||
"{{hthH5}}": urls[1]
|
||||
else: # ky模板
|
||||
url_mapping = {
|
||||
"{{kyPc1}}": categories.get("WEB", [""])[0],
|
||||
"{{kyPc2}}": categories.get("WEB", ["", ""])[1],
|
||||
"{{kyH51}}": categories.get("H5", [""])[0],
|
||||
"{{kyH52}}": categories.get("H5", ["", ""])[1],
|
||||
"{{kyApp1}}": categories.get("全站", [""])[0],
|
||||
"{{kyApp2}}": categories.get("全站", ["", ""])[1],
|
||||
"{{kyTy1}}": categories.get("体育", [""])[0],
|
||||
"{{kyTy2}}": categories.get("体育", ["", ""])[1]
|
||||
}
|
||||
|
||||
return url_mapping
|
||||
|
||||
def change_url(text):
|
||||
|
||||
def extract_urls(text):
|
||||
seo_part_index = text.find("SEO 防拦截域名")
|
||||
relevant_text = text[:seo_part_index] if seo_part_index != -1 else text
|
||||
pattern = r'(?:\n|^)\s*([^\n]*?)\s*(https?://[^\s]+)'
|
||||
matches = re.findall(pattern, relevant_text)
|
||||
return [(context.strip(), url) for context, url in matches]
|
||||
|
||||
|
||||
def change_url(text, hth_template_path='/www/wwwroot/change_url/hth.js.template',
|
||||
ky_template_path='/www/wwwroot/change_url/ky.js.template'):
|
||||
try:
|
||||
urls = extract_urls(text)
|
||||
urls_with_context = extract_urls(text)
|
||||
expected_filename = None
|
||||
|
||||
if len(urls) >= 10:
|
||||
js_content = read_file('ky.js.template')
|
||||
ky_url_mapping = {
|
||||
"{{kyApp1}}": urls[0],
|
||||
"{{kyApp2}}": urls[1],
|
||||
"{{kyPc1}}": urls[2],
|
||||
"{{kyPc2}}": urls[3],
|
||||
"{{kyH51}}": urls[4],
|
||||
"{{kyH52}}": urls[5]
|
||||
}
|
||||
updated_content = replace_urls(js_content, ky_url_mapping)
|
||||
expected_filename = 'ky.js'
|
||||
write_file(expected_filename, updated_content)
|
||||
elif len(urls) == 6:
|
||||
js_content = read_file('hth.js.template')
|
||||
is_seo = 'SEO' in text
|
||||
hth_url_mapping = get_hth_url_mapping(urls, is_seo)
|
||||
updated_content = replace_urls(js_content, hth_url_mapping)
|
||||
expected_filename = 'hth.js'
|
||||
write_file(expected_filename, updated_content)
|
||||
if '代理' in text:
|
||||
is_seo = False
|
||||
else:
|
||||
expected_filename = 'unknown.js' # 或者选择适合的默认文件名
|
||||
is_seo = True
|
||||
|
||||
if len(urls_with_context) in [4, 6]:
|
||||
template_path = hth_template_path
|
||||
template_type = 'hth'
|
||||
elif len(urls_with_context) == 8:
|
||||
template_path = ky_template_path
|
||||
template_type = 'ky'
|
||||
else:
|
||||
return False, 'unknown.js'
|
||||
|
||||
js_content = read_file(template_path)
|
||||
url_mapping = get_url_mapping(urls_with_context, is_seo, template_type)
|
||||
updated_content = replace_urls(js_content, url_mapping)
|
||||
expected_filename = template_path.replace('.template', '')
|
||||
write_file(expected_filename, updated_content)
|
||||
|
||||
# 如果一切顺利,返回 True 和预期的文件名
|
||||
return True, expected_filename
|
||||
except Exception as e:
|
||||
# 如果在过程中发生任何异常,打印错误并返回 False 和预期的文件名
|
||||
print(f"An error occurred: {e}")
|
||||
return False, expected_filename if expected_filename else 'unknown.js'
|
||||
|
@ -188,11 +188,8 @@ class Application(QMainWindow):
|
||||
self.top_panel.addWidget(self.dateEdit)
|
||||
|
||||
def setup_date_update_timer(self):
|
||||
# 创建一个新的定时器
|
||||
self.date_update_timer = QTimer(self)
|
||||
# 设置定时器触发的槽函数
|
||||
self.date_update_timer.timeout.connect(self.update_date_edit)
|
||||
# 启动定时器
|
||||
self.start_date_update_timer()
|
||||
|
||||
def start_date_update_timer(self):
|
||||
@ -202,14 +199,10 @@ class Application(QMainWindow):
|
||||
self.date_update_timer.start(interval if interval > 0 else 86400000) # 86400000ms = 24小时
|
||||
|
||||
def update_date_edit(self):
|
||||
# 更新日期选择器的日期为当前日期
|
||||
self.dateEdit.setDate(QDate.currentDate())
|
||||
# 强制刷新控件
|
||||
self.dateEdit.update()
|
||||
# 更新日期范围
|
||||
self.update_date_range()
|
||||
# 设置定时器每24小时触发一次
|
||||
self.date_update_timer.start(86400000)
|
||||
self.start_date_update_timer()
|
||||
|
||||
def update_date_range(self):
|
||||
today = QDate.currentDate()
|
||||
|
Loading…
Reference in New Issue
Block a user