| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- # -*- coding: utf-8 -*-
- import os
- import yaml
- # 无分组版本, 需要
- # 读取的 yaml 的文件名
- bitz_file_name = 'Bitz Net.yaml'
- xfltd_file_name = 'XFLTD.yaml'
- partiot_file_name = 'index.php.yaml'
- file_name_list = ['Bitz Net.yaml', 'XFLTD.yaml', 'index.php.yaml']
- # 需要的代理地区
- need_list = [
- 'HK', '香港', 'TW', '台湾', '新加坡', '日本', '马来西亚', '菲律宾'
- ]
- # 创建 config.yaml 模版, 读出来的 proxies 和 proxy-groups 存到对应的地方, rules 不要了
- config_template = {
- "mixed-port": 7890,
- "allow-lan": True,
- "bind-address": "*",
- "mode": "rule",
- "log-level": "info",
- "external-controller": "127.0.0.1:9090",
- "secret": "",
- "dns": {
- "enable": False,
- "ipv6": False,
- "nameserver": [],
- "fallback": []
- },
- "proxies": [],
- "proxy-groups": [],
- }
- def process_yaml_file(is_other):
- temp_data = []
- for file_name in file_name_list:
- if not os.path.exists(file_name):
- return
- data = None
- with open(file_name, 'r', encoding='utf-8') as file:
- data = yaml.safe_load(file)
- if not data:
- return
- proxies = data['proxies']
- for proxy in proxies:
- for keyword in need_list:
- if is_other:
- if keyword not in proxy['name'] and proxy not in temp_data:
- temp_data.append(proxy)
- else:
- if keyword in proxy['name'] and proxy not in temp_data:
- 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
- if __name__ == '__main__':
- for i in range(2):
- process_yaml_file(i)
- with open(f'config{i + 1}.yaml', 'w', encoding='utf-8') as file:
- yaml.dump(config_template, file, allow_unicode=True, default_flow_style=False)
- print('done!')
|