更新 .gitea/workflows/convert_surge_to_gogost.py
All checks were successful
SurgeToGoGostConverter / convert (push) Successful in 4s
All checks were successful
SurgeToGoGostConverter / convert (push) Successful in 4s
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
def convert_surge_to_gogost(input_path, output_path):
|
||||
print(f"正在转换: {input_path} -> {output_path}")
|
||||
with open(input_path, 'r') as infile, open(output_path, 'w') as outfile:
|
||||
for line in infile:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
# 跳过空行和注释
|
||||
continue
|
||||
|
||||
# DOMAIN 规则 -> 直接匹配域名
|
||||
@@ -30,7 +31,7 @@ def convert_surge_to_gogost(input_path, output_path):
|
||||
for domain in domain_set_file:
|
||||
domain = domain.strip()
|
||||
if domain.startswith('.'):
|
||||
outfile.write(f"*{domain}\n") # 子域名匹配
|
||||
outfile.write(f"*{domain}\n")
|
||||
else:
|
||||
outfile.write(f"{domain}\n")
|
||||
|
||||
@@ -48,15 +49,18 @@ def convert_surge_to_gogost(input_path, output_path):
|
||||
else:
|
||||
outfile.write(f"# 未识别规则: {line}\n")
|
||||
|
||||
# 执行转换并指定文件路径1
|
||||
input_dir = "./surge" # 替换为你的 Surge 规则文件夹路径
|
||||
output_dir = "./gogost" # 替换为转换后文件的输出路径
|
||||
# 执行转换并指定文件路径
|
||||
input_dir = "./surge" # Surge 规则文件夹路径
|
||||
output_dir = "./gogost" # 转换后文件的输出路径
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
# 逐个转换指定目录中的 Surge 规则文件
|
||||
for filename in os.listdir(input_dir):
|
||||
if filename.endswith(".list"): # 假设规则文件以 .list 结尾
|
||||
if filename.endswith(".list"):
|
||||
input_path = os.path.join(input_dir, filename)
|
||||
output_filename = filename.replace(".list", ".txt") # 将文件后缀从 .list 改为 .txt
|
||||
output_path = os.path.join(output_dir, output_filename)
|
||||
output_path = os.path.join(output_dir, filename.replace(".list", ".txt"))
|
||||
convert_surge_to_gogost(input_path, output_path)
|
||||
|
||||
# 列出目标目录中的文件,验证输出是否成功
|
||||
print("转换完成。目标目录中的文件列表:")
|
||||
print(os.listdir(output_dir))
|
||||
Reference in New Issue
Block a user