페북 수집·지표·저장 파이프라인 정리
수집: - pages + posts 두 actor 병렬 호출 (facebook-pages-scraper, facebook-posts-scraper) - 저장 필드 슬림화: 페이지 메타에서 likes/rating/email/phone/address 제거 (followers/reviews와 중복이거나 클리닉 raw_data에 이미 있음) - 게시물 저장은 캡션 160자 + likes/reactions/shares/views/isVideo/timestamp만 지표 계산 위치 이동: 리포트 시점 → 수집 시점: - recent_post_age / post_frequency / engagement 를 transform_for_storage에서 결정적으로 산출해 DB에 박음 (재계산 불필요) - 저장된 게시물은 LLM용 캡션·타입 2필드만 — 추가 슬림 단계 제거 리팩토링: - services/facebook_audit.py 신설 (instagram_audit 패턴) — _build_overrides의 인라인 클로저(_fb_page_patch)와 analysis.py의 _fb_post_metrics 분리 - collect.py / enrichment.py 가 transform_for_storage를 호출하도록 엔게이지먼트 표기: - 범위(min~max)로 표시, 전부 0인 지표는 제외 - 댓글은 actor 미제공이라 "댓글 거의 없음" 고정 부가 콘텐츠 유형: - top_content_type 은 캡션 본문 주제 추론이 필요해 LLM에 위임 - report_prompt.txt 에 facebook_audit.pages[].top_content_type 작성 지침 추가 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4f756cf001
commit
652265cd19
6 files changed
+152
-22
No files matched your search
+36
-11
@@ -9,6 +9,10 @@ APIFY_BASE = "https://api.apify.com/v2"
|
||||
IG_PROFILE_ACTOR = "coderx~instagram-profile-scraper-bio-posts"
|
||||
IG_HIGHLIGHTS_ACTOR = "igview-owner~instagram-highlights-scraper"
|
||||
|
||||
# Facebook: pages + posts 두 actor 직접 호출.
|
||||
FB_PAGES_ACTOR = "apify~facebook-pages-scraper"
|
||||
FB_POSTS_ACTOR = "apify~facebook-posts-scraper"
|
||||
|
||||
|
||||
def _ig_username(url: str) -> str:
|
||||
return urlparse(url).path.strip("/").split("/")[0] if "://" in url else url.lstrip("@")
|
||||
@@ -19,7 +23,7 @@ class ApifyClient:
|
||||
self.token = token
|
||||
self.wait_for_finish = wait_for_finish
|
||||
|
||||
async def _run_actor(self, actor_id: str, input_data: dict) -> list[dict]:
|
||||
async def _run_actor(self, actor_id: str, input_data: dict, limit: int = 20) -> list[dict]:
|
||||
resp = await http_request(
|
||||
HTTPMethod.POST,
|
||||
url=f"{APIFY_BASE}/acts/{actor_id}/runs",
|
||||
@@ -35,7 +39,7 @@ class ApifyClient:
|
||||
items_resp = await http_request(
|
||||
HTTPMethod.GET,
|
||||
url=f"{APIFY_BASE}/datasets/{dataset_id}/items",
|
||||
params={"token": self.token, "limit": 20},
|
||||
params={"token": self.token, "limit": limit},
|
||||
label=f"apify-dataset-{dataset_id}",
|
||||
)
|
||||
if not items_resp or not items_resp.is_success:
|
||||
@@ -116,26 +120,47 @@ class ApifyClient:
|
||||
# }
|
||||
|
||||
async def fetch_facebook_page(self, page_url: str) -> dict | None:
|
||||
items = await self._run_actor("apify~facebook-pages-scraper", {"startUrls": [{"url": page_url}]})
|
||||
items = await self._run_actor(FB_PAGES_ACTOR, {"startUrls": [{"url": page_url}]})
|
||||
return items[0] if items else None
|
||||
|
||||
async def fetch_facebook_posts(self, page_url: str, limit: int = 20) -> list[dict]:
|
||||
return await self._run_actor(
|
||||
FB_POSTS_ACTOR, {"startUrls": [{"url": page_url}], "resultsLimit": limit}, limit=limit,
|
||||
)
|
||||
|
||||
async def get_facebook_page(self, page_url: str) -> dict | None:
|
||||
page = await self.fetch_facebook_page(page_url)
|
||||
if not page:
|
||||
# pages·posts 두 task 병렬 호출 (posts 실패해도 page만 있으면 진행)
|
||||
page, posts = await asyncio.gather(
|
||||
self.fetch_facebook_page(page_url),
|
||||
self.fetch_facebook_posts(page_url),
|
||||
return_exceptions=True,
|
||||
)
|
||||
if isinstance(page, Exception) or not page:
|
||||
return None
|
||||
if isinstance(posts, Exception):
|
||||
posts = []
|
||||
return {
|
||||
"pageName": page.get("title") or page.get("name"),
|
||||
"profileImage": page.get("profilePictureUrl") or page.get("profilePhoto") or page.get("profilePic"),
|
||||
"pageUrl": page.get("pageUrl", page_url),
|
||||
"followers": page.get("followers", 0),
|
||||
"likes": page.get("likes", 0),
|
||||
"following": page.get("followings", 0),
|
||||
"reviews": page.get("ratingCount", 0),
|
||||
"categories": page.get("categories", []),
|
||||
"email": page.get("email"),
|
||||
"phone": page.get("phone"),
|
||||
"website": page.get("website"),
|
||||
"address": page.get("address"),
|
||||
"website": page.get("website") or page.get("websites"),
|
||||
"intro": page.get("intro"),
|
||||
"rating": page.get("rating"),
|
||||
"latestPosts": [
|
||||
{
|
||||
"text": (p.get("text") or "")[:160],
|
||||
"likes": p.get("likes", 0),
|
||||
"reactions": p.get("topReactionsCount", 0),
|
||||
"shares": p.get("shares", 0),
|
||||
"views": p.get("viewsCount") or 0,
|
||||
"isVideo": p.get("isVideo", False),
|
||||
"timestamp": p.get("time") or p.get("timestamp"),
|
||||
}
|
||||
for p in (posts or []) if isinstance(p, dict)
|
||||
],
|
||||
}
|
||||
|
||||
async def fetch_tiktok_profile(self, url: str) -> list[dict]:
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
- clinic_snapshot 의 overall_rating/total_reviews/staff_count/location/certifications/lead_doctor 는 강남언니({gangnam_unni}) 데이터의 값을 그대로 사용.
|
||||
- **instagram_audit.accounts 는 반드시 빈 배열 []로 두세요.** 계정 정보는 시스템이 수집 데이터로 직접 채우니 LLM은 만들지 말고, instagram_audit.diagnosis(진단)만 작성하세요.
|
||||
- facebook_audit.pages: KR 페북({facebook})·영문 페북({facebook_en}) 데이터가 있으면 **각각 별도 페이지**로 넣고, url/page_name/followers 등은 그 데이터 그대로. language/label 동일 규칙.
|
||||
- facebook_audit.pages[].top_content_type 은 해당 페이지 latestPosts의 **캡션·미디어를 읽고** 주로 올리는 콘텐츠를 의미 기반으로 짧게 묘사하세요 (예: "Before/After 사진 + 환자 여정 Reels", "이벤트·프로모션 카드뉴스", "다국어 시술 소개"). 단순 "동영상/이미지 위주"가 아니라 **무슨 주제**인지 쓰세요. (recent_post_age·post_frequency·engagement 수치는 시스템이 덮어쓰니 대략 적어도 됩니다.)
|
||||
- 위 수치·URL·이름은 제공된 데이터에서 그대로 쓰고 절대 지어내지 마세요.
|
||||
|
||||
## 기타 채널 현황 (other_channels) 작성 지침
|
||||
|
||||
Reference in new issue
Block a user