-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import re | ||
|
||
# 读取文件 | ||
with open("./rules.yaml", "r") as file: | ||
rules = file.read() | ||
|
||
# 创建文件夹 | ||
os.makedirs("./rules", exist_ok=True) | ||
|
||
# 正则 | ||
regex = r"# ======= (.*?) ======= #" | ||
result = re.split(regex, rules) | ||
|
||
# 拆分 yaml文件 | ||
for i in range(1, len(result), 2): | ||
ruleName = result[i] | ||
ruleContent = result[i + 1] | ||
|
||
# 创建对应名称的文件 | ||
filePath = f"./rules/{ruleName}.yaml" | ||
|
||
# 添加原始文件内容 | ||
splitYAML = f"{result[0]}\n# ======= {ruleName} ======= #\n{ruleContent}" | ||
|
||
# 写入文件 | ||
with open(filePath, "w") as file: | ||
file.write(splitYAML) |