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