From 33fe2b4e0a919623bc09ce41464d4cf1b6791c6f Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:17:07 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E7=BB=BC=E5=90=88=E6=9B=B4=E6=96=B0.p?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/综合更新.py | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/py/综合更新.py b/py/综合更新.py index 290e83b..aeac075 100644 --- a/py/综合更新.py +++ b/py/综合更新.py @@ -396,26 +396,7 @@ with open("4.txt", "w", encoding="utf-8") as output: with open(os.path.join('playlist', file_path), 'r', encoding="utf-8") as file: content = file.read() output.write(content + '\n\n') -print("电视频道成功写入") - -#################文本排序 -# 打开原始文件读取内容,并写入新文件 -with open('4.txt', 'r', encoding='utf-8') as file: - lines = file.readlines() -# 定义一个函数,用于提取每行的第一个数字 -def extract_first_number(line): - match = re.search(r'\d+', line) - return int(match.group()) if match else float('inf') -# 对列表中的行进行排序 -# 按照第一个数字的大小排列,如果不存在数字则按中文拼音排序 -sorted_lines = sorted(lines, key=lambda x: (not 'CCTV' in x, extract_first_number(x) if 'CCTV' in x else lazy_pinyin(x.strip()))) -# 将排序后的行写入新的utf-8编码的文本文件,文件名基于原文件名 -output_file_path = "sorted_" + os.path.basename(file_path) -# 写入新文件 -with open('2.txt', "w", encoding="utf-8") as file: - for line in sorted_lines: - file.write(line) -print(f"文件已排序并保存为: {output_file_path}") +print("频道合并成功") 以下为组播IP流畅性检测 import cv2 @@ -424,7 +405,7 @@ from tqdm import tqdm # 初始化酒店源字典 detected_ips = {} # 存储文件路径 -file_path = "2.txt" +file_path = "4.txt" output_file_path = "2.txt" def get_ip_key(url): """从URL中提取IP地址,并构造一个唯一的键""" @@ -486,6 +467,27 @@ with open(output_file_path, 'w', encoding='utf-8') as output_file: for ip_key, result in detected_ips.items(): print(f"IP Key: {ip_key}, Status: {result['status']}") + +#################文本排序 +# 打开原始文件读取内容,并写入新文件 +with open('2.txt', 'r', encoding='utf-8') as file: + lines = file.readlines() +# 定义一个函数,用于提取每行的第一个数字 +def extract_first_number(line): + match = re.search(r'\d+', line) + return int(match.group()) if match else float('inf') +# 对列表中的行进行排序 +# 按照第一个数字的大小排列,如果不存在数字则按中文拼音排序 +sorted_lines = sorted(lines, key=lambda x: (not 'CCTV' in x, extract_first_number(x) if 'CCTV' in x else lazy_pinyin(x.strip()))) +# 将排序后的行写入新的utf-8编码的文本文件,文件名基于原文件名 +output_file_path = "sorted_" + os.path.basename(file_path) +# 写入新文件 +with open('2.txt', "w", encoding="utf-8") as file: + for line in sorted_lines: + file.write(line) +print(f"文件已排序并保存) + + ######################################################################################################################################################################################## ################################################################定义关键词分割规则 def check_and_write_file(input_file, output_file, keywords):