mirror of
https://github.com/SpaceTimee/Cealing-Host.git
synced 2025-07-14 05:12:30 +08:00
25 lines
612 B
Python
25 lines
612 B
Python
import json
|
|
import toml
|
|
from collections import defaultdict
|
|
|
|
|
|
def convert_host_to_toml(host_path, toml_path):
|
|
with open(host_path) as host_file:
|
|
host_rules = json.load(host_file)
|
|
|
|
toml_rules = defaultdict(dict)
|
|
|
|
for host_rule in host_rules:
|
|
domains, sni, ip = host_rule
|
|
|
|
for domain in domains:
|
|
toml_rules["alter_hostname"][domain] = sni
|
|
toml_rules["hosts"][domain] = ip
|
|
|
|
with open(toml_path, "w") as toml_file:
|
|
toml.dump(toml_rules, toml_file)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
convert_host_to_toml("Cealing-Host.json", "Cealing-Host.toml")
|