-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
56 lines (51 loc) · 1.79 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
import os
import sys
import traceback
import function
# 载入依赖项
try:
with open("input.json","r+",encoding='UTF-8') as file:
jsonContext = json.loads("".join(file.readlines()))
except:
print('请将正确的 JSON 文件置于当前目录下,并命名为 input.json !')
os.system("pause")
sys.exit()
# 载入 json
try:
jsonContext = function.structuralBody(jsonContext['结构体'])
except ZeroDivisionError:
sys.exit()
except:
print('错误:在转换时发生了未知错误。如果不出意外,可能是您提供了不正确的 JSON 文件\n相关错误日志如下:\n')
print(traceback.format_exc())
os.system("pause")
sys.exit()
# 取得结果
with open("ans.json","w+",encoding='UTF-8') as file:
file.write(
json.dumps(
jsonContext,
sort_keys=True,indent=4
,separators=(', ', ': '),
ensure_ascii=False
)
)
# 输出展开版本的 json
with open("指令.txt","w+",encoding='UTF-8') as file:
jsonContext = json.dumps(jsonContext,ensure_ascii=False,separators=(',', ':'))
file.write(
'/Execute <Target> ~ ~ ~ Tellraw @s ' + jsonContext +
'\n' + '/Execute <Target> ~ ~ ~ Titleraw @s <Title|Subtitle|Actionbar> ' +
jsonContext + '\n\n' + 'Execute <Target> ~ ~ ~ Tellraw @s ' + jsonContext +
'\n' + 'Execute <Target> ~ ~ ~ Titleraw @s <Title|Subtitle|Actionbar> ' +
jsonContext
)
# 输出指令
print('完成:已将 input.json 转换为指令')
print('已展开的 JSON 形式保存在当前目录下的 ans.json 中')
print('指令已保存在当前目录下的 指令.txt 中\n')
print('Made By Happy2018new')
os.system("pause")
sys.exit()
# 善后