o2o-site-AEO/solution/backend/services/search_console_alerts.py
Mina Choi 11d30bb3d1 [chore] solution,admin,ontology: 코드 주석을 한 줄로 — 히스토리 주석 삭제
여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다.

- ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제
- 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다
- eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다

파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이).
site·frontend·admin tsc, site vitest 105 passed

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 16:05:19 +09:00

46 lines
1.7 KiB
Python

"""Teams Workflow 수신용."""
from datetime import timedelta
import httpx
from common.logger import LOG
def alert_reason(row, now, days: int) -> str | None:
if row.alerted_at and now - row.alerted_at < timedelta(days=1):
return None
if row.error_code:
return f"조회/제출 실패: {row.error_code}"
if (row.inspection or {}).get("verdict") == "PASS":
return None
if now - row.published_at >= timedelta(days=days):
return f"발행 후 {days}일 이상 색인 미확인"
return None
async def send_alert(webhook_url: str, page_url: str, reason: str) -> bool:
if not webhook_url:
return False
if not webhook_url.startswith("https://"):
LOG.w("[search-console] ALERT_URL_INVALID")
return False
payload = {"type": "message", "attachments": [{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": None,
"content": {"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard", "version": "1.2", "body": [
{"type": "TextBlock", "text": "Google 색인 확인 필요", "weight": "Bolder"},
{"type": "TextBlock", "text": page_url, "wrap": True},
{"type": "TextBlock", "text": reason, "wrap": True},
]},
}]}
try:
async with httpx.AsyncClient(timeout=10, follow_redirects=False) as client:
response = await client.post(webhook_url, json=payload)
response.raise_for_status()
return True
except httpx.HTTPError:
# webhook 주소 자체가 인증 수단이므로 예외 문자열도 로그에 남기지 않는다.
LOG.w("[search-console] ALERT_DELIVERY_FAILED")
return False