Monitor: parole chiave di esclusione dagli avvisi
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
43c935f395
commit
fdb954b92e
5 files changed
+71
-3
No files matched your search
@@ -208,6 +208,15 @@ class Monitor:
|
||||
print(f"[monitor] {name}: {err}")
|
||||
seen = set(self.state.get("seen", []))
|
||||
items = [it for it in items if it["ref"] not in seen]
|
||||
excluded = [w.strip().lower() for w in str(self.settings.get("monitor_escludi") or "").split(",") if w.strip()]
|
||||
if excluded:
|
||||
def _keep(it: dict) -> bool:
|
||||
hay = f"{it.get('chi', '')} {it.get('testo', '')}".lower()
|
||||
return not any(w in hay for w in excluded)
|
||||
skipped = [it for it in items if not _keep(it)]
|
||||
items = [it for it in items if _keep(it)]
|
||||
for it in skipped:
|
||||
print(f"[monitor] escluso per parola chiave: {it['fonte']} {it['chi']}")
|
||||
self.state.setdefault("seen", []).extend(it["ref"] for it in items)
|
||||
alerts = self._classify(items) if items else []
|
||||
for a in alerts:
|
||||
|
||||
@@ -35,6 +35,7 @@ DEFAULTS: dict[str, Any] = {
|
||||
"monitor_annuncia": True, # annuncia a voce gli avvisi
|
||||
"monitor_intervallo": 60, # secondi tra un controllo e l'altro
|
||||
"monitor_regole": "", # cosa merita attenzione (vuoto = regole predefinite)
|
||||
"monitor_escludi": "", # parole/frasi (separate da virgola) che escludono un messaggio dagli avvisi
|
||||
}
|
||||
|
||||
SECRET_KEYS = ("anthropic_api_key", "local_api_key", "telegram_api_hash")
|
||||
|
||||
@@ -165,6 +165,8 @@ class SettingsDialog(QDialog):
|
||||
from .monitor import DEFAULT_RULES
|
||||
self.mon_rules = QLineEdit(s.get("monitor_regole") or ""); self.mon_rules.setPlaceholderText(DEFAULT_RULES[:110] + "…")
|
||||
form5.addRow("Cosa merita un avviso", self.mon_rules)
|
||||
self.mon_excl = QLineEdit(s.get("monitor_escludi") or ""); self.mon_excl.setPlaceholderText("es. newsletter, offerta, gruppo Calcetto, Amazon — parole separate da virgola, cercate in mittente, chat e testo")
|
||||
form5.addRow("Escludi dagli avvisi", self.mon_excl)
|
||||
root.addLayout(form5)
|
||||
|
||||
btns = QHBoxLayout(); btns.addStretch()
|
||||
@@ -348,6 +350,7 @@ class SettingsDialog(QDialog):
|
||||
"monitor_annuncia": self.mon_say.isChecked(),
|
||||
"monitor_intervallo": int(self.mon_int.currentData() or 60),
|
||||
"monitor_regole": self.mon_rules.text().strip(),
|
||||
"monitor_escludi": self.mon_excl.text().strip(),
|
||||
}
|
||||
if self.tg_hash.text().strip():
|
||||
values["telegram_api_hash"] = self.tg_hash.text().strip()
|
||||
|
||||
Reference in new issue
Block a user