89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
import os
|
|
import re
|
|
|
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
def parse_rss_feeds(filepath):
|
|
"""解析 rss_feeds.txt 格式:源名称|RSS地址"""
|
|
entries = []
|
|
with open(filepath, 'r', encoding='utf-8') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if not line or line.startswith('#'):
|
|
continue
|
|
if '|' in line:
|
|
name, url = line.split('|', 1)
|
|
entries.append((name.strip(), url.strip()))
|
|
return entries
|
|
|
|
def parse_high_quality(filepath):
|
|
"""解析高质量列表格式:公众号名称\t公众号ID\tRSS订阅地址"""
|
|
entries = []
|
|
with open(filepath, 'r', encoding='utf-8') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if not line or line.startswith('#'):
|
|
continue
|
|
parts = line.split('\t')
|
|
if len(parts) >= 3:
|
|
name = parts[0].strip()
|
|
url = parts[2].strip()
|
|
if url:
|
|
entries.append((name, url))
|
|
return entries
|
|
|
|
def main():
|
|
feeds_path = os.path.join(base_dir, 'rss_feeds.txt')
|
|
hq_path = os.path.join(base_dir, 'rss_feed_list_高质量 copy.txt')
|
|
output_path = os.path.join(base_dir, 'rss_feeds_merged.txt')
|
|
|
|
feeds_entries = parse_rss_feeds(feeds_path)
|
|
hq_entries = parse_high_quality(hq_path)
|
|
|
|
all_entries = feeds_entries + hq_entries
|
|
|
|
seen_urls = set()
|
|
unique_entries = []
|
|
for name, url in all_entries:
|
|
if url not in seen_urls:
|
|
seen_urls.add(url)
|
|
unique_entries.append((name, url))
|
|
|
|
english_entries = []
|
|
wechat_entries = []
|
|
for name, url in unique_entries:
|
|
if 'werss.yynnice.top' in url:
|
|
wechat_entries.append((name, url))
|
|
else:
|
|
english_entries.append((name, url))
|
|
|
|
wechat_entries.sort(key=lambda x: x[0].lower())
|
|
english_entries.sort(key=lambda x: x[0].lower())
|
|
|
|
with open(output_path, 'w', encoding='utf-8') as f:
|
|
f.write('# 军事科技RSS订阅源列表(合并版)\n')
|
|
f.write('# 格式:<源名称>|<RSS地址>\n')
|
|
f.write('# 以#开头的行是注释,会自动忽略\n')
|
|
f.write('# 空行也会自动跳过\n')
|
|
f.write('# 合并时间: 2026-05-29\n')
|
|
f.write('\n')
|
|
|
|
if english_entries:
|
|
f.write('# 英文军事源\n')
|
|
for name, url in english_entries:
|
|
f.write(f'{name}|{url}\n')
|
|
f.write('\n')
|
|
|
|
if wechat_entries:
|
|
f.write('# 中文微信公众号源\n')
|
|
for name, url in wechat_entries:
|
|
f.write(f'{name}|{url}\n')
|
|
|
|
print(f'英文源: {len(english_entries)} 个')
|
|
print(f'中文微信公众号源: {len(wechat_entries)} 个')
|
|
print(f'总计: {len(english_entries) + len(wechat_entries)} 个')
|
|
print(f'已写入: {output_path}')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|