| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- # -*- coding: utf-8 -*-
- import os
- import json
- import shutil
- import yaml # 保留导入 yaml 模块
- # 新文件夹名称
- 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) # 使用 yaml 模块加载 YAML 文件
- if not data:
- print(f"Error reading {config_path}")
- exit(1)
- config_name_serial_start = 1
- port_start = 56000
- for proxy in data['proxies']:
- if '剩余流量' in proxy['name']:
- continue
- if '套餐到期' in proxy['name']:
- continue
- password = 'password'
- if proxy['type'] == 'vmess':
- password = 'uuid'
- # 构建 SingBox 配置模板
- config_template = {
- "log": {
- "level": "info"
- },
- "inbounds": [
- {
- "type": "mixed",
- "listen": "::",
- "listen_port": port_start
- }
- ],
- "outbounds": [
- {
- "type": proxy['type'],
- "tag": f'proxy_{config_name_serial_start}',
- "server": proxy['server'],
- "server_port": proxy['port'],
- f'{password}': proxy.setdefault('uuid', proxy.setdefault('password', '')),
- "tls": {
- "enabled": False
- }
- }
- ],
- "route": {
- "rules": [
- {
- "type": "default",
- "outbound": f'proxy_{config_name_serial_start}'
- }
- ]
- }
- }
- config_name = f"config{str(config_name_serial_start)}.json"
- save_path = os.path.join(new_folder_path, config_name)
- with open(save_path, 'w', encoding='utf-8') as file:
- json.dump(config_template, file, ensure_ascii=False, indent=4)
- config_name_serial_start += 1
- port_start += 1
- print("OK")
|