WIP: channel-brand merge + Optional 모델 완화 + collect_extras rename + mock_urls 영문 채널 51건
머지 본체: - 5채널 외 부가 수집(틱톡/IG·FB EN/네이버 카페/카카오톡) - 브랜드 자산/채널 로고 Vision 분석 - ReportInput/PlanInput에 신규 채널 필드 추가 - ChannelBrandingRule literal "missing" → "N/A" 후속 로컬 작업 (분리 커밋 예정): - fix(report): ClinicSnapshot/YouTubeAudit/Instagram*/Facebook* required→Optional (LLM null 응답 대응) - refactor: enrichment.py → collect_extras.py (네이밍 명확화) - data(mock_urls): 38개 병원 영문 채널 51건 추가 + 78개 필드 캐노니컬 순서 정규화 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
aff2b2720d
27 files changed
+3005
-223
No files matched your search
@@ -263,6 +263,19 @@ async def save_hospital_raw_data(hospital_id: str, data: dict, analysis_run_id:
|
||||
await _insert_hospital_history(hospital_id, analysis_run_id)
|
||||
|
||||
|
||||
async def merge_hospital_raw_data(hospital_id: str, patch: dict) -> None:
|
||||
"""hospital_baseinfo.raw_data를 읽어 patch를 top-level 병합 후 저장 (read-modify-write).
|
||||
부가 수집 단계들이 순차로 raw_data에 키를 덧붙일 때 사용."""
|
||||
row = await fetchone("SELECT raw_data FROM hospital_baseinfo WHERE hospital_id = %s", (hospital_id,))
|
||||
raw = row["raw_data"] if row else None
|
||||
raw_data = json.loads(raw) if isinstance(raw, str) else (raw or {})
|
||||
raw_data.update(patch)
|
||||
await execute(
|
||||
"UPDATE hospital_baseinfo SET raw_data = %s WHERE hospital_id = %s",
|
||||
(json.dumps(raw_data, ensure_ascii=False), hospital_id),
|
||||
)
|
||||
|
||||
|
||||
async def get_market_analysis(analysis_run_id: str) -> dict:
|
||||
rows = await fetchall(
|
||||
"SELECT analysis_type, data FROM market_analysis WHERE analysis_run_id = %s AND status = 'done'",
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import os
|
||||
import asyncio
|
||||
import logging
|
||||
from http import HTTPMethod
|
||||
import httpx
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
REQUEST_TIMEOUT = 60
|
||||
|
||||
|
||||
@@ -37,3 +40,48 @@ async def http_request(
|
||||
print(f" [error] {label} → {e}")
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
async def _run_optional_step(coro, label: str) -> None:
|
||||
"""부가 단계 실행 헬퍼: 예외를 삼키고 경고 로그만 남겨 호출측 흐름이 멈추지 않게 격리."""
|
||||
try:
|
||||
await coro
|
||||
except Exception as e:
|
||||
logger.warning("%s 실패 (무시하고 진행): %s", label, e)
|
||||
|
||||
|
||||
def _normalize_homepage(url: str) -> str:
|
||||
"""URL을 scheme/www/끝슬래시 제거 + 소문자로 정규화 (homepage 매칭용)."""
|
||||
u = (url or "").strip().lower()
|
||||
for p in ("https://", "http://"):
|
||||
if u.startswith(p):
|
||||
u = u[len(p):]
|
||||
if u.startswith("www."):
|
||||
u = u[4:]
|
||||
return u.rstrip("/")
|
||||
|
||||
|
||||
# SSL 인증서가 www.* 에만 유효한 도메인 — bare 도메인이면 사용자 클릭 시 브라우저 SSL warning 뜸.
|
||||
_WWW_REQUIRED = ("gangnamunni.com", "facebook.com", "instagram.com", "toxnfill.com")
|
||||
|
||||
|
||||
def _with_scheme(u: str | None) -> str | None:
|
||||
"""scheme 없는 URL에 https:// 보정 (수집기/링크 표시용). 빈 값은 None.
|
||||
+ 중첩된 https://가 끼어있으면 마지막 URL만 추출 (LLM이 가끔 'https://www.X/https://Y' 같이 만듦).
|
||||
+ SSL 엄격 도메인(gangnamunni/facebook/instagram)은 www. 자동 보강."""
|
||||
if not u:
|
||||
return None
|
||||
u = u.strip()
|
||||
# 'https://www.facebook.com/https://facebook.com/X' 같은 중첩 → 마지막 'http(s)://' 부터 잘라 사용
|
||||
last = max(u.rfind("https://"), u.rfind("http://"))
|
||||
if last > 0:
|
||||
u = u[last:]
|
||||
if "://" not in u:
|
||||
u = "https://" + u
|
||||
# scheme 뒤가 www. 없이 SSL 엄격 도메인이면 www. 추가
|
||||
for dom in _WWW_REQUIRED:
|
||||
for scheme in ("https://", "http://"):
|
||||
if u.startswith(scheme + dom):
|
||||
u = scheme + "www." + u[len(scheme):]
|
||||
break
|
||||
return u
|
||||
Reference in new issue
Block a user