From 85a4fa85aec066ed27a4cc44b13bda7d7148d7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sk=C3=BDpala?= Date: Wed, 17 May 2023 17:03:26 +0200 Subject: [PATCH] Default json content from python file --- hrochobot/utils/data.py | 4 +++- hrochobot/utils/json_templates.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 hrochobot/utils/json_templates.py diff --git a/hrochobot/utils/data.py b/hrochobot/utils/data.py index 1cb208d..5ef4bd5 100644 --- a/hrochobot/utils/data.py +++ b/hrochobot/utils/data.py @@ -2,13 +2,15 @@ from typing import Any import json import os.path +from hrochobot.utils.json_templates import TEMPLATES + EXAMPLE_DATA = "data.example" DATA_FOLDER = "TODO" def load_json(filename: str): filename += ".json" if not os.path.exists(filename): - filename = os.path.join(EXAMPLE_DATA, os.path.basename(filename)) + return json.loads(TEMPLATES[os.path.basename(filename)]) with open(filename) as f: content = json.load(f) diff --git a/hrochobot/utils/json_templates.py b/hrochobot/utils/json_templates.py new file mode 100644 index 0000000..3aaaa30 --- /dev/null +++ b/hrochobot/utils/json_templates.py @@ -0,0 +1,3 @@ +TEMPLATES = { + 'roles.json' : '{"secret_roles": {}}', +}