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.
74 lines
2.2 KiB
74 lines
2.2 KiB
# -*- coding: utf-8 -*-
|
|
import os
|
|
import yaml
|
|
import shutil
|
|
|
|
# 分组关键词
|
|
proxy_split_group = {
|
|
"US": ['us', '美国', 'la-', '加拿大'],
|
|
'UE': ['uk', '英国'],
|
|
'ASIA': ['hk', '香港', 'tw', '台湾', 'sg', '新加坡', '马来西亚', '澳门', '泰国', '日本', 'jp', '韩国']
|
|
}
|
|
|
|
# 新文件夹名称
|
|
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
|
|
|
|
out_data = {}
|
|
|
|
for i in data.setdefault('proxies'):
|
|
for group_name, group_keywords in proxy_split_group.items():
|
|
if any(keyword in i['name'].lower() for keyword in group_keywords):
|
|
if group_name not in out_data:
|
|
out_data[group_name] = []
|
|
if i['name'] not in [x['name'] for x in out_data[group_name]]:
|
|
out_data[group_name].append(i)
|
|
|
|
for g_name, g_proxy in out_data.items():
|
|
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-groups": [{'name': 'all', 'type': 'select', 'proxies': []}],
|
|
}
|
|
for proxy in g_proxy:
|
|
config_template['proxies'].append(proxy)
|
|
config_template['proxy-groups'][0]['proxies'].append(proxy['name'])
|
|
|
|
config_path = os.path.join(new_folder_path, f'{g_name.lower()}.yaml')
|
|
with open(config_path, 'w', encoding='utf-8') as file:
|
|
yaml.dump(config_template, file, allow_unicode=True, sort_keys=False)
|
|
|
|
print('OK')
|
|
|