인스타 highlights/계정 수집 개선 (VIEW actor + 코드로 계정 구성)
- apify: 프로필 coderx, 하이라이트 igview actor로 교체. highlights/category/ following(followsCount)/profileImage(hdProfilePicUrl)/latestPosts.mediaType 수집. reel 스크래퍼 제거, post 스크래퍼 비활성화(주석) - instagram_audit.py(신규): KR·EN 계정 hard 필드를 수집 데이터로 구성 - analysis: _build_overrides에서 위 함수로 계정 구성, _patch_report가 accounts를 코드값으로 주입 (LLM은 diagnosis만, 프롬프트에서 accounts는 []로 두게 지시) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
163e9d1c02
commit
4f756cf001
4 files changed
+116
-80
No files matched your search
@@ -4,6 +4,7 @@ from common.db import fetchone, execute, fetch_raw, get_analysis_raw_data, save_
|
||||
from integrations.llm.llm_service import LLMService
|
||||
from integrations.llm.prompt import report_prompt, plan_prompt
|
||||
from integrations.llm.schemas.report import ReportOutput
|
||||
from services.instagram_audit import build_instagram_accounts
|
||||
from integrations.llm.schemas.plan import PlanOutput
|
||||
from models.status import AnalysisStatus
|
||||
|
||||
@@ -134,14 +135,10 @@ async def _build_overrides(analysis_run_id: str) -> dict:
|
||||
"review_count": lead.get("reviews"),
|
||||
}
|
||||
|
||||
# ── instagram ─────────────────────────────────────────────────────────────
|
||||
ig_patch: dict = {}
|
||||
if instagram.get("username"): ig_patch["handle"] = instagram["username"]
|
||||
if instagram.get("posts"): ig_patch["posts"] = instagram["posts"]
|
||||
if instagram.get("followers"): ig_patch["followers"] = instagram["followers"]
|
||||
if instagram.get("following"): ig_patch["following"] = instagram["following"]
|
||||
if instagram.get("bio"): ig_patch["bio"] = instagram["bio"]
|
||||
if instagram.get("username"): ig_patch["profile_link"] = f"https://www.instagram.com/{instagram['username']}/"
|
||||
# ── instagram (KR·EN 계정을 코드에서 구성 → LLM 출력 무시하고 교체) ──────────────
|
||||
ig_patch = build_instagram_accounts(
|
||||
instagram, hospital.get("instagramEn") or {}, hospital.get("channelLogos") or {},
|
||||
)
|
||||
|
||||
# ── facebook ──────────────────────────────────────────────────────────────
|
||||
fb_patch: dict = {}
|
||||
@@ -178,7 +175,7 @@ async def _build_overrides(analysis_run_id: str) -> dict:
|
||||
if snapshot:
|
||||
overrides["clinic_snapshot"] = snapshot
|
||||
if ig_patch:
|
||||
overrides["instagram_audit"] = {"accounts": [ig_patch]}
|
||||
overrides["instagram_audit"] = {"accounts": ig_patch}
|
||||
if fb_patch:
|
||||
overrides["facebook_audit"] = {"pages": [fb_patch]}
|
||||
if yt_patch:
|
||||
@@ -200,6 +197,8 @@ def _deep_merge(base: dict, overrides: dict) -> dict:
|
||||
|
||||
def _patch_report(result: ReportOutput, overrides: dict) -> ReportOutput:
|
||||
merged = _deep_merge(result.model_dump(), overrides)
|
||||
# 인스타 계정은 프롬프트에서 LLM이 []로 두게 했고, 코드가 수집 데이터로 채운다 (데이터 없으면 빈 리스트)
|
||||
merged.setdefault("instagram_audit", {})["accounts"] = (overrides.get("instagram_audit") or {}).get("accounts") or []
|
||||
return ReportOutput(**merged)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
"""Instagram audit 계정(KR·EN)을 수집 데이터로 구성.
|
||||
fix 값(handle/followers/highlights/content_format 등)은 전부 코드에서 박는다 — LLM 출력 무시."""
|
||||
|
||||
_MEDIA = {"GraphImage": "이미지", "GraphSidecar": "카드뉴스", "GraphVideo": "영상/릴스"}
|
||||
|
||||
|
||||
def _content_format(data: dict) -> str:
|
||||
"""latestPosts 미디어 타입으로 콘텐츠 포맷 도출 (표기 순서는 _MEDIA 정의 순서로 고정)."""
|
||||
present = {_MEDIA.get(p.get("type")) for p in (data.get("latestPosts") or [])}
|
||||
return "/".join(m for m in _MEDIA.values() if m in present)
|
||||
|
||||
|
||||
def _logo_desc(channel_logos: dict, channel: str) -> str:
|
||||
"""channelLogos(비전 결과)에서 해당 채널 로고 설명만 가져온다."""
|
||||
for c in (channel_logos or {}).get("channel_logos", []):
|
||||
if c.get("channel") == channel:
|
||||
return c.get("logo_description") or ""
|
||||
return ""
|
||||
|
||||
|
||||
def _account(data: dict, language: str, label: str, channel: str, channel_logos: dict) -> dict:
|
||||
"""스크래퍼 수집값으로 InstagramAccount 전 필드를 구성."""
|
||||
handle = data.get("username") or ""
|
||||
return {
|
||||
"handle": handle,
|
||||
"language": language,
|
||||
"label": label,
|
||||
"posts": data.get("posts", 0),
|
||||
"followers": data.get("followers", 0),
|
||||
"following": data.get("following", 0),
|
||||
"category": data.get("category", ""),
|
||||
"profile_link": f"https://www.instagram.com/{handle}/" if handle else "",
|
||||
"highlights": data.get("highlights") or [],
|
||||
"reels_count": 0, # 릴스 스크래퍼 미사용
|
||||
"content_format": _content_format(data),
|
||||
"profile_photo": _logo_desc(channel_logos, channel),
|
||||
"bio": data.get("bio", ""),
|
||||
}
|
||||
|
||||
|
||||
def build_instagram_accounts(instagram: dict, instagram_en: dict, channel_logos: dict) -> list[dict]:
|
||||
"""KR·EN 인스타 계정 리스트 구성 (username 있는 것만)."""
|
||||
accounts: list[dict] = []
|
||||
if instagram.get("username"):
|
||||
accounts.append(_account(instagram, "KR", "인스타그램 KR", "Instagram", channel_logos))
|
||||
if instagram_en.get("username"):
|
||||
accounts.append(_account(instagram_en, "EN", "인스타그램 EN", "Instagram EN", channel_logos))
|
||||
return accounts
|
||||
Reference in new issue
Block a user