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.
66 lines
1.7 KiB
66 lines
1.7 KiB
# -*- coding: utf-8 -*-
|
|
# 生成代理节点, 并过滤, 传入 merge.yaml 生成 config.yaml
|
|
|
|
import yaml
|
|
|
|
file_name = 'merge.yaml'
|
|
|
|
need_nodes = ['日本', 'JP', '新加坡', 'SG', '台湾', 'TW', '韩国', '澳门', '马来西亚', '澳大利亚', '菲律宾']
|
|
|
|
config_file = {
|
|
"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": [{"name": "GLOBAL", "type": "select", "proxies": []}],
|
|
}
|
|
|
|
|
|
def process_yaml_file():
|
|
proxy_list = []
|
|
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 any(x in proxy['name'] for x in ['剩余流量', '套餐到期', '有效期']):
|
|
continue
|
|
|
|
if any(node in proxy['name'] for node in need_nodes):
|
|
proxy_list.append(proxy)
|
|
|
|
proxy_list_sorted = sorted(proxy_list, key=lambda x: x['name'] if 'name' in x else '')
|
|
|
|
return proxy_list_sorted
|
|
|
|
|
|
def create_config_file(proxy_list_sorted):
|
|
config_file['proxies'] = proxy_list_sorted
|
|
|
|
for proxy_list in proxy_list_sorted:
|
|
config_file['proxy-groups'][0]['proxies'].append(proxy_list['name'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
proxy_list_sorted = process_yaml_file()
|
|
|
|
create_config_file(proxy_list_sorted)
|
|
|
|
with open(f'config.yaml', 'w', encoding='utf-8') as file:
|
|
yaml.dump(config_file, file, allow_unicode=True, default_flow_style=False)
|
|
|
|
print('done!')
|
|
|