blob: 990b1c9afe0fd9d7a35ea15a2695cb03d08b8c53 (
plain)
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
|
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
|