Files

27 lines
599 B
Python
Raw Permalink Normal View History

2026-01-20 10:13:51 +08:00
'''
读取物质定义文件列表和内容
'''
2026-01-02 21:47:28 +08:00
import json
def readMatterList() -> dict:
with open("resources/matters/list.json", "r", encoding="utf8") as f:
2026-01-02 21:47:28 +08:00
text = f.read()
result = json.loads(text)
return result
2026-01-20 08:45:50 +08:00
matter_list = readMatterList()
2026-01-02 21:47:28 +08:00
def readMatter(id: str):
path = matter_list.get(id, -1)
if (path == -1):
return {"message": f"No Matter {id}"}
with open(f"resources/matters/{path}.json", "r", encoding="utf8") as f:
text = f.read()
result = json.loads(text)
2026-01-20 08:45:50 +08:00
return {"message": "OK", "content": result}