diff --git a/agent-office/app/scheduler.py b/agent-office/app/scheduler.py index b75fe31..b9bdce5 100644 --- a/agent-office/app/scheduler.py +++ b/agent-office/app/scheduler.py @@ -29,6 +29,12 @@ async def _run_insta_schedule(): if agent: await agent.on_schedule() + +async def _run_insta_trends_collect(): + agent = AGENT_REGISTRY.get("insta") + if agent: + await agent.on_command("collect_trends", {}) + async def _run_lotto_schedule(): agent = AGENT_REGISTRY.get("lotto") if agent: @@ -68,6 +74,7 @@ def init_scheduler(): id="stock_ai_news_sentiment", ) scheduler.add_job(_run_insta_schedule, "cron", hour=9, minute=30, id="insta_pipeline") + scheduler.add_job(_run_insta_trends_collect, "cron", hour=9, minute=0, id="insta_trends_collect") scheduler.add_job(_run_lotto_schedule, "cron", day_of_week="mon", hour=9, minute=0, id="lotto_curate") scheduler.add_job(_run_youtube_research, "cron", hour=9, minute=0, id="youtube_research") scheduler.add_job(_send_youtube_weekly_report, "cron", day_of_week="mon", hour=8, minute=0, id="youtube_weekly_report") diff --git a/insta-lab/app/main.py b/insta-lab/app/main.py index 9cd4f1c..195eae5 100644 --- a/insta-lab/app/main.py +++ b/insta-lab/app/main.py @@ -99,11 +99,16 @@ class ExtractRequest(BaseModel): categories: Optional[list[str]] = None -async def _bg_extract(task_id: str, categories: list[str]): +async def _bg_extract(task_id: str, categories: Optional[list[str]] = None): try: db.update_task(task_id, "processing", 10, "추출 중") - for cat in categories: - keyword_extractor.extract_for_category(cat, limit=KEYWORDS_PER_CATEGORY) + prefs_rows = db.get_preferences() + weights = {p["category"]: p["weight"] for p in prefs_rows} + if categories: + # 사용자가 카테고리 명시한 경우만 그 서브셋으로 균등 가중치 (override) + weights = {c: 1.0 for c in categories} + total = KEYWORDS_PER_CATEGORY * max(1, len([w for w in weights.values() if w > 0])) + keyword_extractor.extract_with_weights(weights, total_limit=total) db.update_task(task_id, "succeeded", 100, "완료", result_id=0) except Exception as e: logger.exception("extract failed")