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/merge2config.py

69 lines
1.7 KiB

# -*- coding: utf-8 -*-
import os
import yaml
# 无分组版本, 需要
# 读取的 yaml 的文件名
file_name = 'merge.yaml'
# 创建 config.yaml 模版, 读出来的 proxies 和 proxy-groups 存到对应的地方, rules 不要了
config_template = {
"mixed-port": 7890,
"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": [],
}
def process_yaml_file():
temp_data = []
data = None
with open(file_name, 'r', encoding='utf-8') as file:
data = yaml.safe_load(file)
if not data:
print(f"Error reading {file_name}")
return
proxies = data['proxies']
for proxy in proxies:
if '剩余流量' in proxy['name']:
continue
if '套餐到期' in proxy['name']:
continue
print('{}: {}'.format(file_name, proxy['name']))
temp_data.append(proxy)
sorted_proxies = sorted(temp_data, key=lambda x: x['name'] if 'name' in x else '')
if temp_data:
config_template['proxies'] = sorted_proxies
# 创建 proxy-groups 中的 select 组,包含所有 proxies
select_group = {
"name": "GLOBAL",
"type": "select",
"proxies": [proxy['name'] for proxy in sorted_proxies]
}
config_template['proxy-groups'].append(select_group)
if __name__ == '__main__':
process_yaml_file()
with open(f'config.yaml', 'w', encoding='utf-8') as file:
yaml.dump(config_template, file, allow_unicode=True, default_flow_style=False)
print('done!')