Backup automatico script del 2026-01-18 07:00

This commit is contained in:
2026-01-18 07:00:02 +01:00
parent 4555d6615e
commit 9dbe0cfa93
8 changed files with 339 additions and 57 deletions

View File

@@ -476,41 +476,41 @@ def analyze_freeze(chat_ids: Optional[List[str]] = None, debug_mode: bool = Fals
LOGGER.info(" Nuova fascia %d: %s - %s", i+1, start.strftime("%d/%m %H:%M"), end.strftime("%d/%m %H:%M"))
if should_notify:
# Costruisci messaggio con dettagli sulle nuove fasce orarie
period_details = []
if has_new_periods:
for start, end in new_periods[:3]: # Max 3 fasce nel messaggio
if start.date() == end.date():
period_details.append(f"{start.strftime('%d/%m %H:%M')}-{end.strftime('%H:%M')}")
else:
period_details.append(f"{start.strftime('%d/%m %H:%M')}-{end.strftime('%d/%m %H:%M')}")
msg_parts = [
"❄️ <b>ALLERTA GELO</b>\n",
f"📍 {html.escape(LOCATION_NAME)}\n\n",
f"Minima prevista (entro {HOURS_AHEAD}h): <b>{min_temp_val:.1f}°C</b>\n",
f"📅 Quando: <b>{html.escape(fmt_dt(min_temp_time))}</b>",
]
if period_details:
msg_parts.append("\n🕒 Fasce orarie: " + ", ".join(period_details))
msg_parts.append("\n\n<i>Proteggere piante e tubature esterne.</i>")
msg = "".join(msg_parts)
# Costruisci messaggio con dettagli sulle nuove fasce orarie
period_details = []
if has_new_periods:
for start, end in new_periods[:3]: # Max 3 fasce nel messaggio
if start.date() == end.date():
period_details.append(f"{start.strftime('%d/%m %H:%M')}-{end.strftime('%H:%M')}")
else:
period_details.append(f"{start.strftime('%d/%m %H:%M')}-{end.strftime('%d/%m %H:%M')}")
msg_parts = [
"❄️ <b>ALLERTA GELO</b>\n",
f"📍 {html.escape(LOCATION_NAME)}\n\n",
f"Minima prevista (entro {HOURS_AHEAD}h): <b>{min_temp_val:.1f}°C</b>\n",
f"📅 Quando: <b>{html.escape(fmt_dt(min_temp_time))}</b>",
]
if period_details:
msg_parts.append("\n🕒 Fasce orarie: " + ", ".join(period_details))
msg_parts.append("\n\n<i>Proteggere piante e tubature esterne.</i>")
msg = "".join(msg_parts)
ok = telegram_send_html(msg, chat_ids=chat_ids)
if ok:
LOGGER.info("Allerta gelo inviata. Tmin=%.1f°C at %s, nuove fasce: %d",
min_temp_val, min_temp_time.isoformat(), len(new_periods))
# Aggiorna le fasce notificate
for start, end in new_periods:
notified_periods.append({
"start": start.isoformat(),
"end": end.isoformat(),
})
LOGGER.info("Allerta gelo inviata. Tmin=%.1f°C at %s, nuove fasce: %d",
min_temp_val, min_temp_time.isoformat(), len(new_periods))
# Aggiorna le fasce notificate
for start, end in new_periods:
notified_periods.append({
"start": start.isoformat(),
"end": end.isoformat(),
})
else:
LOGGER.warning("Allerta gelo NON inviata (token mancante o errore Telegram).")
else:
LOGGER.info("Gelo già notificato (nessuna nuova fascia oraria, peggioramento < 2°C). Tmin=%.1f°C", min_temp_val)
LOGGER.info("Gelo già notificato (nessuna nuova fascia oraria, peggioramento < 2°C). Tmin=%.1f°C", min_temp_val)
state.update({
"alert_active": True,