mirror of
https://github.com/SpaceTimee/Cealing-Host.git
synced 2025-09-14 13:56:47 +08:00
1.1.4.15 -> 1.1.4.16 第1次更新
This commit is contained in:
parent
57688700ec
commit
f785a42d86
24
.github/workflows/convert_host_to_toml.py
vendored
Normal file
24
.github/workflows/convert_host_to_toml.py
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
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")
|
35
.github/workflows/convert_host_to_toml.yaml
vendored
Normal file
35
.github/workflows/convert_host_to_toml.yaml
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
name: Convert Host To Toml
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
convert_host_to_toml:
|
||||
name: Convert Host To Toml
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Fetch Github Folder
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
sparse-checkout: .github
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.x
|
||||
check-latest: true
|
||||
|
||||
- name: Install Toml
|
||||
run: pip install "toml"
|
||||
|
||||
- name: Convert Host To Toml
|
||||
run: |
|
||||
cd ".github/workflows"
|
||||
python "convert_host_to_toml.py"
|
||||
|
||||
- name: Release Toml Host
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: Cealing-Host.toml
|
||||
token: ${{ secrets.GH_TOKEN }}
|
23
.github/workflows/generate-toml-and-release.yaml
vendored
23
.github/workflows/generate-toml-and-release.yaml
vendored
@ -1,23 +0,0 @@
|
||||
name: Generate toml config and release
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*.*.*.*"
|
||||
jobs:
|
||||
generate:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: generate toml file
|
||||
run: |
|
||||
pip install toml
|
||||
python ./.github/workflows/generate.py
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: config
|
||||
path: |
|
||||
./*.json
|
||||
./*.toml
|
||||
- uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifacts: "./*.json, ./*.toml"
|
37
.github/workflows/generate.py
vendored
37
.github/workflows/generate.py
vendored
@ -1,37 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
import json
|
||||
import toml
|
||||
|
||||
|
||||
def convert_json_to_toml(json_file_path, toml_file_path):
|
||||
# 读取JSON文件
|
||||
with open(json_file_path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
# 初始化TOML数据结构
|
||||
toml_data = {"alter_hostname": {}, "hosts": {}}
|
||||
|
||||
# 处理每个条目
|
||||
for entry in data:
|
||||
domains, alter_host, ip = entry
|
||||
|
||||
# 处理alter_hostname部分
|
||||
for domain in domains:
|
||||
toml_data["alter_hostname"][domain] = alter_host
|
||||
|
||||
# 处理hosts部分
|
||||
for domain in domains:
|
||||
toml_data["hosts"][domain] = ip
|
||||
|
||||
# 写入TOML文件
|
||||
with open(toml_file_path, "w", encoding="utf-8") as f:
|
||||
toml.dump(toml_data, f)
|
||||
|
||||
|
||||
# 使用示例
|
||||
if __name__ == "__main__":
|
||||
for filename_base in [
|
||||
"Cealing-Host-R",
|
||||
"Cealing-Host",
|
||||
]:
|
||||
convert_json_to_toml(filename_base + ".json", filename_base + ".toml")
|
Loading…
Reference in New Issue
Block a user