You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
auto/archive/clash-multi/GenerateClashConfigSingleNo...

64 lines
1.7 KiB

# -*- coding: utf-8 -*-
import os
import yaml
import shutil
# 新文件夹名称
new_folder_name = "config"
downloads_path = os.path.join(os.path.expanduser('~'), 'Downloads')
# 新文件夹的完整路径
new_folder_path = os.path.join(downloads_path, new_folder_name)
# 如果文件夹存在,删除整个文件夹
if os.path.exists(new_folder_path):
shutil.rmtree(new_folder_path)
# 创建新的文件夹
os.makedirs(new_folder_path)
config_path = os.path.join(os.getcwd(), "merge.yaml")
with open(config_path, 'r', encoding='utf-8') as file:
data = yaml.safe_load(file)
if not data:
print(f"Error reading {config_path}")
exit(1)
config_name_serial_start = 1
port_start = 7890
for proxy in data['proxies']:
if '剩余流量' in proxy['name']:
continue
if '套餐到期' in proxy['name']:
continue
config_template = {
"mixed-port": port_start,
"allow-lan": True,
"bind-address": "*",
"mode": "rule",
"log-level": "info",
"external-controller": "0.0.0.0:9090",
"secret": "",
"dns": {
"enable": False,
"ipv6": False,
"nameserver": [],
"fallback": []
},
"proxies": [proxy],
"proxy-groups": [{'name': 'single node', 'type': 'select', 'proxies': [proxy['name']]}],
}
config_name = f"config{str(config_name_serial_start)}.yaml"
save_path = os.path.join(new_folder_path, config_name)
with open(save_path, 'w', encoding='utf-8') as file:
yaml.dump(config_template, file, allow_unicode=True, default_flow_style=False)
config_name_serial_start += 1
# port_start += 1
print(config_name_serial_start-1)
print('OK')