Backup automatico script del 2026-07-19 07:00

This commit is contained in:
2026-07-19 07:00:03 +02:00
parent 927f0d4184
commit 4802b021fe
24 changed files with 686 additions and 213 deletions
+57
View File
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
"""Abilitazione/sospensione notifiche Telegram per script cron meteo e report."""
from __future__ import annotations
import logging
import os
from pathlib import Path
LOGGER = logging.getLogger("telegram_gate")
_CONFIG = Path(__file__).with_name("cron-alerts.env")
def _load_config() -> None:
if not _CONFIG.is_file():
return
try:
for line in _CONFIG.read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
key = key.strip()
value = value.strip().strip('"').strip("'")
if key and key not in os.environ:
os.environ[key] = value
except OSError as exc:
LOGGER.debug("Config non caricata: %s", exc)
_load_config()
def telegram_alerts_enabled() -> bool:
value = os.environ.get("LOOGLE_TELEGRAM_ALERTS", "1").strip().lower()
return value not in ("0", "off", "false", "no", "disabled")
def mirror_alert_to_web(
message: str,
category: str,
severity: str = "warning",
*,
is_html: bool = False,
) -> bool:
if not message or not category:
return False
try:
import sys
sys.path.insert(0, "/home/daniely/docker/shared")
from loogle_core.alert_dispatcher import mirror_to_web
return mirror_to_web(message, category, severity, is_html=is_html)
except Exception as exc:
LOGGER.debug("Mirror WebApp fallito (%s): %s", category, exc)
return False