28 lines
656 B
Python
28 lines
656 B
Python
import json
|
|
from pathlib import Path
|
|
|
|
from config import settings
|
|
|
|
|
|
STORE_PATH = Path(__file__).resolve().parent.parent / "nodes.json"
|
|
|
|
|
|
def load_nodes() -> None:
|
|
if not STORE_PATH.exists():
|
|
return
|
|
try:
|
|
nodes = json.loads(STORE_PATH.read_text(encoding="utf-8"))
|
|
except (OSError, json.JSONDecodeError):
|
|
return
|
|
if isinstance(nodes, list):
|
|
settings.edge_nodes = nodes
|
|
|
|
|
|
def save_nodes() -> None:
|
|
temporary = STORE_PATH.with_suffix(".json.tmp")
|
|
temporary.write_text(
|
|
json.dumps(settings.edge_nodes, ensure_ascii=False, indent=2),
|
|
encoding="utf-8",
|
|
)
|
|
temporary.replace(STORE_PATH)
|