clash_each_node.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import yaml
  4. # 读取当前路径
  5. current_path = os.getcwd()
  6. # 新文件夹名称
  7. new_folder_name = "clash_each_node"
  8. # 新文件夹的完整路径
  9. new_folder_path = os.path.join(current_path, new_folder_name)
  10. # 检查文件夹是否存在,如果不存在则创建
  11. if not os.path.exists(new_folder_path):
  12. os.makedirs(new_folder_path)
  13. config_path = os.path.join(current_path, "merge.yaml")
  14. with open(config_path, 'r', encoding='utf-8') as file:
  15. data = yaml.safe_load(file)
  16. if not data:
  17. print(f"Error reading {config_path}")
  18. exit(1)
  19. config_name_serial_start = 1
  20. port_start = 7890
  21. for proxy in data['proxies']:
  22. if '剩余流量' in proxy['name']:
  23. continue
  24. if '套餐到期' in proxy['name']:
  25. continue
  26. config_template = {
  27. "mixed-port": port_start,
  28. "allow-lan": True,
  29. "bind-address": "*",
  30. "mode": "rule",
  31. "log-level": "info",
  32. "external-controller": "0.0.0.0:9090",
  33. "secret": "",
  34. "dns": {
  35. "enable": False,
  36. "ipv6": False,
  37. "nameserver": [],
  38. "fallback": []
  39. },
  40. "proxies": [proxy],
  41. "proxy-groups": [{'name': 'single node', 'type': 'select', 'proxies': [proxy['name']]}],
  42. }
  43. config_name = f"config{str(config_name_serial_start)}.yaml"
  44. save_path = os.path.join(new_folder_path, config_name)
  45. with open(save_path, 'w', encoding='utf-8') as file:
  46. yaml.dump(config_template, file, allow_unicode=True, default_flow_style=False)
  47. config_name_serial_start += 1
  48. # port_start += 1