Backup automatico script del 2026-07-26 07:00
This commit is contained in:
1 parent
4802b021fe
commit
a9bbb92090
19 files changed
+1086
-550
No files matched your search
@@ -337,7 +337,7 @@ def load_state() -> Dict:
|
||||
return default
|
||||
|
||||
|
||||
def save_state(alert_active: bool, signature: str, casa_data: Optional[Dict] = None, last_notification_utc: Optional[str] = None) -> None:
|
||||
def save_state(alert_active: bool, signature: str, casa_data: Optional[Dict] = None, last_notification_utc: Optional[str] = None, summary: Optional[str] = None) -> None:
|
||||
try:
|
||||
os.makedirs(os.path.dirname(STATE_FILE), exist_ok=True)
|
||||
state_data = {
|
||||
@@ -354,6 +354,8 @@ def save_state(alert_active: bool, signature: str, casa_data: Optional[Dict] = N
|
||||
"casa_first_thr_time": casa_data.get("first_thr_time", ""),
|
||||
"casa_duration_hours": casa_data.get("duration_hours", 0.0),
|
||||
})
|
||||
if summary:
|
||||
state_data["summary"] = summary[:3000]
|
||||
with open(STATE_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(state_data, f, ensure_ascii=False, indent=2)
|
||||
except Exception as e:
|
||||
@@ -1694,7 +1696,15 @@ def analyze_snow(chat_ids: Optional[List[str]] = None, debug_mode: bool = False)
|
||||
msg.append("<i>Fonte dati: Open-Meteo</i>")
|
||||
|
||||
# Unisci con <br> (sarà convertito in \n in telegram_send_html)
|
||||
ok = telegram_send_html("<br>".join(msg), chat_ids=chat_ids)
|
||||
html_msg = "<br>".join(msg)
|
||||
ok = telegram_send_html(html_msg, chat_ids=chat_ids)
|
||||
snow_summary = None
|
||||
try:
|
||||
from webapp_alert import publish_web_alert, message_to_plain
|
||||
snow_summary = message_to_plain(html_msg, is_html=True)
|
||||
publish_web_alert(html_msg, "snow", "warning", is_html=True, title="Allerta neve")
|
||||
except Exception as e:
|
||||
LOGGER.debug("Web summary failed: %s", e)
|
||||
|
||||
# Genera e invia grafico (solo se abbiamo dati per Casa)
|
||||
chart_generated = False
|
||||
@@ -1731,11 +1741,11 @@ def analyze_snow(chat_ids: Optional[List[str]] = None, debug_mode: bool = False)
|
||||
|
||||
# Salva timestamp dell'ultima notifica
|
||||
now_utc = datetime.datetime.now(datetime.timezone.utc)
|
||||
save_state(True, sig, casa_data, last_notification_utc=now_utc.isoformat(timespec="seconds"))
|
||||
save_state(True, sig, casa_data, last_notification_utc=now_utc.isoformat(timespec="seconds"), summary=snow_summary)
|
||||
else:
|
||||
LOGGER.warning("Notifica neve NON inviata (token mancante o errore Telegram).")
|
||||
# Salva comunque lo state (senza aggiornare last_notification_utc)
|
||||
save_state(True, sig, casa_data, last_notification_utc=state.get("last_notification_utc", ""))
|
||||
save_state(True, sig, casa_data, last_notification_utc=state.get("last_notification_utc", ""), summary=snow_summary)
|
||||
else:
|
||||
LOGGER.info("Allerta attiva ma nessun cambiamento significativo. Motivo: %s", change_reason)
|
||||
# Salva lo state anche se non inviamo (per mantenere alert_active e last_notification_utc)
|
||||
|
||||
Reference in new issue
Block a user