From faeb133ecf26ce6447d254ce69659e38c46e5e24 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Mon, 16 Jun 2025 08:12:44 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E9=85=92=E5=BA=97=E6=BA=90=E5=89=AF?= =?UTF-8?q?=E6=9C=AC.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/酒店源副本.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/py/酒店源副本.py b/py/酒店源副本.py index 1bdaf47..d970102 100644 --- a/py/酒店源副本.py +++ b/py/酒店源副本.py @@ -579,27 +579,6 @@ if __name__ == "__main__": except Exception as e: print(f"程序发生错误: {e}") -import re -from pypinyin import lazy_pinyin - -# 打开一个utf-8编码的文本文件 -with open("酒店源.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编码的文本文件 -with open("酒店源.txt", "w", encoding="utf-8") as file: - for line in sorted_lines: - file.write(line) - os.remove("iptv.txt")