mirror of
https://github.com/skoelle/dyndns-updater.git
synced 2026-09-18 00:20:24 +00:00
Add SPEC, PLAN, Dockerfile, compose, env example, app modules, CI workflow
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
log = logging.getLogger("state")
|
||||
|
||||
|
||||
def load(state_path: str):
|
||||
if not os.path.exists(state_path):
|
||||
log.info("Keine vorherige State-Datei gefunden (%s) - Erstlauf.", state_path)
|
||||
return None
|
||||
try:
|
||||
with open(state_path, "r") as f:
|
||||
data = json.load(f)
|
||||
return data.get("last_ip")
|
||||
except (json.JSONDecodeError, OSError) as exc:
|
||||
log.warning("State-Datei konnte nicht gelesen werden (%s): %s", state_path, exc)
|
||||
return None
|
||||
|
||||
|
||||
def save(state_path: str, ip: str):
|
||||
os.makedirs(os.path.dirname(state_path), exist_ok=True)
|
||||
with open(state_path, "w") as f:
|
||||
json.dump({"last_ip": ip}, f)
|
||||
log.info("State gespeichert: last_ip=%s", ip)
|
||||
Reference in New Issue
Block a user