fix: h-lab 수집 단계에서 광고/홍보 댓글 제외

좋아요를 조작한 광고(할인 링크 등)가 좋아요 채우기·후보 상위로 올라와
드래프트 카드에 들어가는 사고가 실제로 났다. 오탐이 더 아프므로 보수적으로
URL·"n% 할인"·"최저가"만 걸러낸다("할인"·"%" 단독 일상 댓글은 통과).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hehihoho3@gmail.com 2026-08-05 15:54:20 +09:00
parent 5295d92dfc
commit 2266d0a3ee

View File

@ -23,6 +23,19 @@ _TAG_RE = re.compile(r"<[^>]+>")
# 후보(candidates)는 분:초가 아예 없는 댓글만 쓰므로, 여기만 막으면 화면에서 완전히 빠진다. # 후보(candidates)는 분:초가 아예 없는 댓글만 쓰므로, 여기만 막으면 화면에서 완전히 빠진다.
MAX_TIMES = 3 MAX_TIMES = 3
# 광고/홍보 댓글 판별 — 좋아요를 조작한 광고가 ➕좋아요 채우기·후보 상위에 올라와
# 드래프트 카드로 뽑히는 사고 방지. 오탐이 더 아프므로 보수적으로:
# URL, "n% 할인", "최저가"만 본다("할인"·"%" 단독인 일상 댓글은 통과).
_AD_RE = re.compile(
r"https?://|www\.|tinyurl\.|bit\.ly|"
r"\d+\s*%\s*할인|최저가"
)
def _is_ad(text: str) -> bool:
"""광고/홍보 댓글이면 True — fetch_comments 가 수집 단계에서 걸러낸다."""
return bool(_AD_RE.search(plain_text(text)))
def plain_text(html: str) -> str: def plain_text(html: str) -> str:
"""YouTube textDisplay(HTML) → 평문. <br>→줄바꿈, 나머지 태그 제거.""" """YouTube textDisplay(HTML) → 평문. <br>→줄바꿈, 나머지 태그 제거."""
@ -61,11 +74,14 @@ def fetch_comments(url: str, *, timeout: float = 180.0) -> List[Dict]:
if not data.get("success"): if not data.get("success"):
raise RuntimeError(f"h-lab 응답 실패: {data.get('message')}") raise RuntimeError(f"h-lab 응답 실패: {data.get('message')}")
out: List[Dict] = [] out: List[Dict] = []
for i, c in enumerate(data.get("data") or []): for c in data.get("data") or []:
text = str(c.get("text") or "")
if _is_ad(text): # 광고는 수집 단계에서 제외 — 어떤 추천 경로로도 카드가 못 된다
continue
out.append({ out.append({
"idx": i, "idx": len(out),
"authorName": str(c.get("authorName") or ""), "authorName": str(c.get("authorName") or ""),
"text": str(c.get("text") or ""), "text": text,
"likeCount": int(c.get("likeCount") or 0), "likeCount": int(c.get("likeCount") or 0),
"replyCount": int(c.get("replyCount") or 0), "replyCount": int(c.get("replyCount") or 0),
"publishedAt": str(c.get("publishedAt") or ""), "publishedAt": str(c.get("publishedAt") or ""),