Keenetic SSH: standalone Telegram bot for Keenetic router SSH control

Made-with: Cursor
This commit is contained in:
Андрей Бобырев
2026-04-24 12:01:05 +03:00
commit 788477d5c6
13 changed files with 554 additions and 0 deletions

20
keenetic_ssh/database.py Normal file
View File

@@ -0,0 +1,20 @@
import json, logging
from pathlib import Path
logger = logging.getLogger("keenetic_ssh")
def load_json(path: Path, default=None):
if default is None: default = {}
if not isinstance(path, Path): path = Path(path)
try:
if path.exists():
t = path.read_text(encoding="utf-8")
if t.strip(): return json.loads(t)
return default
except Exception as e:
logger.error(f"load_json {path}: {e}")
return default
def save_json(path: Path, data):
if not isinstance(path, Path): path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")