quicktool/singbox_merge_rules.py

26 lines
926 B
Python

import json
def merge_rules(singbox_file, rules_file, output_file):
# Read the singbox configuration
with open(singbox_file, 'r', encoding='utf-8') as f:
singbox_config = json.load(f)
# Read the rules
with open(rules_file, 'r', encoding='utf-8') as f:
rules_config = json.load(f)
# Merge and replace the rules into singbox_merged.json
# singbox_config['route']['rules'] = rules_config['route']['rules'] + singbox_config['route']['rules']
singbox_config['route']['rules'] = rules_config['route']['rules']
# Write the merged configuration
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(singbox_config, f, ensure_ascii=False, indent=2)
# Usage
singbox_file = 'singbox.json'
rules_file = 'singbox_rules.json'
output_file = 'singbox_merged.json'
merge_rules(singbox_file, rules_file, output_file)
print(f"Merged configuration saved to {output_file}")