feat(ext): Фаза 3 — чекер обновлений (только доклад) + watch_seen/heartbeat/дайджест

ext_check: обходит источники (новый период ФГИС по зонам, новые приказы pravo, недоступность),
ТОЛЬКО докладывает — state.json НЕ трогает (инвариант в тесте, red-green). watch_seen (дедуп),
reports/, watch.log, heartbeat. email_service.send_operator_digest — письмо оператору только
при новостях (тишина=норма). 7 тестов.
This commit is contained in:
anor
2026-07-18 01:38:44 +10:00
parent e99faadb1e
commit 3a92013600
4 changed files with 336 additions and 0 deletions
+25
View File
@@ -15,6 +15,31 @@ SMTP_USER = os.environ.get("SMTP_USER", "")
SMTP_PASS = os.environ.get("SMTP_PASS", "")
def send_operator_digest(to_email: str, subject: str, html: str) -> bool:
"""Дайджест оператору о новостях внешних источников (чекер ext_check). True при успехе."""
if not SMTP_USER or not SMTP_PASS:
logger.warning("SMTP not configured, skipping operator digest to %s", to_email)
return False
if not to_email:
return False
msg = MIMEMultipart("alternative")
from email.header import Header
msg["Subject"] = subject
msg["From"] = f"{Header('Сметный ассистент', 'utf-8').encode()} <{SMTP_USER}>"
msg["To"] = to_email
msg.attach(MIMEText(html, "html", "utf-8"))
try:
context = ssl.create_default_context()
with smtplib.SMTP_SSL(SMTP_HOST, SMTP_PORT, context=context, timeout=10) as server:
server.login(SMTP_USER, SMTP_PASS)
server.sendmail(SMTP_USER, to_email, msg.as_string())
logger.info("Operator digest sent to %s", to_email)
return True
except Exception as e: # noqa: BLE001
logger.error("Failed to send operator digest to %s: %s", to_email, e)
return False
def send_verification_code(to_email: str, code: str) -> bool:
"""Send 6-digit verification code to email. Returns True on success."""
if not SMTP_USER or not SMTP_PASS: