summaryrefslogtreecommitdiff
path: root/ATRI/plugins/console/data_source.py
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/console/data_source.py')
-rw-r--r--ATRI/plugins/console/data_source.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/ATRI/plugins/console/data_source.py b/ATRI/plugins/console/data_source.py
new file mode 100644
index 0000000..8fe6c04
--- /dev/null
+++ b/ATRI/plugins/console/data_source.py
@@ -0,0 +1,56 @@
+import os
+import json
+from pathlib import Path
+from datetime import datetime
+
+from ATRI.service import Service
+
+
+CONSOLE_DIR = Path(".") / "data" / "database" / "console"
+os.makedirs(CONSOLE_DIR, exist_ok=True)
+
+
+is_connect = False
+
+
+class Console(Service):
+
+ def __init__(self):
+ Service.__init__(self, "控制台")
+
+ @staticmethod
+ def record_data(data: dict) -> None:
+ now_time = datetime.now().strftime("%Y-%m-%d")
+ file_name = f"{now_time}-runtime.json"
+ path = CONSOLE_DIR / file_name
+ if not path.is_file():
+ with open(path ,"w", encoding="utf-8") as w:
+ w.write(json.dumps(list()))
+ temp_data = list()
+
+ temp_data: list = json.loads(path.read_bytes())
+ temp_data.append(data)
+ with open(path, "w", encoding="utf-8") as w:
+ w.write(json.dumps(temp_data, indent=4))
+
+ @staticmethod
+ def load_data() -> list:
+ now_time = datetime.now().strftime("%Y-%m-%d")
+ file_name = f"{now_time}-runtime.json"
+ path = CONSOLE_DIR / file_name
+ if not path.is_file():
+ with open(path, "w", encoding="utf-8") as w:
+ w.write(json.dumps(list()))
+ return list()
+
+ data: list = json.loads(path.read_bytes())
+ return data
+
+ @staticmethod
+ def store_connect_stat(i: bool):
+ global is_connect
+ is_connect = i
+
+ @staticmethod
+ def is_connect() -> bool:
+ return is_connect