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
@@ -1,11 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""DEPRECATED 2026-07-25 (ADR-019).
|
||||
|
||||
Sostituito da ``meteo-alert imminent`` (layer NWP 0–120′ in meteo-alert).
|
||||
Il cron è disabilitato. Per forzare questo script legacy:
|
||||
FORCE_LEGACY_NOWCAST_120M=1 python3 nowcast_120m_alert.py
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
@@ -15,6 +22,14 @@ import requests
|
||||
from dateutil import parser
|
||||
from open_meteo_client import open_meteo_get
|
||||
|
||||
if os.environ.get("FORCE_LEGACY_NOWCAST_120M", "").strip() != "1":
|
||||
print(
|
||||
"DEPRECATED: use `meteo-alert imminent` (ADR-019). "
|
||||
"Set FORCE_LEGACY_NOWCAST_120M=1 to run this script.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(0)
|
||||
|
||||
# =========================
|
||||
# CONFIG
|
||||
# =========================
|
||||
@@ -129,14 +144,12 @@ def telegram_send_markdown(message: str, chat_ids: Optional[List[str]] = None) -
|
||||
return False
|
||||
|
||||
try:
|
||||
from telegram_gate import mirror_alert_to_web, telegram_alerts_enabled
|
||||
from telegram_gate import telegram_alerts_enabled
|
||||
except ImportError:
|
||||
telegram_alerts_enabled = lambda: True # type: ignore
|
||||
mirror_alert_to_web = lambda *a, **k: False # type: ignore
|
||||
|
||||
if not telegram_alerts_enabled():
|
||||
LOGGER.info("Telegram sospeso: skip nowcast_120m")
|
||||
mirror_alert_to_web(message, "nowcast_120m", "warning", is_html=False)
|
||||
return False
|
||||
|
||||
token = load_bot_token()
|
||||
@@ -169,15 +182,6 @@ def telegram_send_markdown(message: str, chat_ids: Optional[List[str]] = None) -
|
||||
except Exception as e:
|
||||
LOGGER.exception("Errore invio Telegram chat_id=%s: %s", chat_id, e)
|
||||
|
||||
if ok_any:
|
||||
try:
|
||||
import sys
|
||||
sys.path.insert(0, "/home/daniely/docker/shared")
|
||||
from loogle_core.alert_dispatcher import mirror_to_web
|
||||
mirror_to_web(message, "nowcast_120m", "warning", is_html=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return ok_any
|
||||
|
||||
|
||||
@@ -991,17 +995,26 @@ def main(chat_ids: Optional[List[str]] = None, debug_mode: bool = False) -> None
|
||||
)
|
||||
|
||||
ok = telegram_send_markdown(msg, chat_ids=chat_ids)
|
||||
if ok:
|
||||
LOGGER.info("Notifica inviata.")
|
||||
# Salva state con eventi attivi aggiornati
|
||||
state["active_events"] = active_events
|
||||
web_ok = False
|
||||
try:
|
||||
from webapp_alert import publish_web_alert
|
||||
web_ok = bool(publish_web_alert(msg, "nowcast_120m", "warning", is_html=False, state=state))
|
||||
except Exception as e:
|
||||
LOGGER.debug("Web summary failed: %s", e)
|
||||
|
||||
# Salva state con eventi attivi aggiornati
|
||||
state["active_events"] = active_events
|
||||
if ok or web_ok:
|
||||
state["last_sent_utc"] = now_utc.isoformat(timespec="seconds")
|
||||
save_state(state)
|
||||
LOGGER.info("Notifica consegnata (%s).", "Telegram" if ok else "WebApp")
|
||||
else:
|
||||
LOGGER.error("Notifica NON inviata (token/telegram).")
|
||||
# Salva comunque lo state aggiornato
|
||||
state["active_events"] = active_events
|
||||
save_state(state)
|
||||
LOGGER.warning("Notifica NON consegnata (Telegram/WebApp).")
|
||||
try:
|
||||
from webapp_alert import remember_summary, message_to_plain
|
||||
remember_summary(state, message_to_plain(msg, is_html=False))
|
||||
except Exception:
|
||||
pass
|
||||
save_state(state)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user