backend rework- full test 1
This commit is contained in:
23
modules/persistence.py
Normal file
23
modules/persistence.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
BASE_PATH = os.path.join(os.path.dirname(__file__), "..", "persistence")
|
||||
BASE_PATH = os.path.abspath(BASE_PATH)
|
||||
|
||||
|
||||
def save_dict(name, data):
|
||||
path = os.path.join(BASE_PATH, f"{name}.json")
|
||||
os.makedirs(BASE_PATH, exist_ok=True)
|
||||
with open(path, "w") as f:
|
||||
json.dump(data, f, default=str, indent=2)
|
||||
|
||||
def load_dict(name):
|
||||
path = os.path.join(BASE_PATH, f"{name}.json")
|
||||
if os.path.exists(path):
|
||||
with open(path, "r") as f:
|
||||
return json.load(f)
|
||||
return {} # fallback falls Datei fehlt
|
||||
|
||||
# no persistence but global variable important for tracking the esp-connection over runtime
|
||||
esp_conn_infos = {"ip_global": None, "ip_local": None, "last_seen": None, "connection_valid": False}
|
||||
Reference in New Issue
Block a user