From 7fd57e61b4173ccb7f8bae4d1e9845c4c38f1a7f Mon Sep 17 00:00:00 2001 From: JOUNGWOOK KWON Date: Mon, 30 Mar 2026 15:45:54 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20/idea=20RSS=20=EC=86=8C=EC=8A=A4=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EB=B3=B5=EC=9B=90=20+=2015=EC=B4=88=20?= =?UTF-8?q?=ED=83=80=EC=9E=84=EC=95=84=EC=9B=83=20=ED=8F=B4=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 검색 성공 시 소스 표시, 15초 초과 시 키워드만으로 저장 후 진행. Co-Authored-By: Claude Sonnet 4.6 --- bots/scheduler.py | 49 +++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/bots/scheduler.py b/bots/scheduler.py index 3d74f8f..6db88d3 100644 --- a/bots/scheduler.py +++ b/bots/scheduler.py @@ -742,25 +742,31 @@ async def cmd_idea(update: Update, context: ContextTypes.DEFAULT_TYPE): await update.message.reply_text("❌ 키워드를 입력하세요.") return - # 네트워크 없이 즉시 topic_data 생성 - if not corner: - corner = _guess_corner(keyword, keyword) - - topic_data = { - 'topic': keyword, - 'description': f"{keyword}에 대한 최신 정보와 분석", - 'source': 'idea', - 'source_name': '직접 입력', - 'source_url': '', - 'published_at': datetime.now().strftime('%Y-%m-%d'), - 'corner': corner, - 'quality_score': 85, - 'search_demand_score': 9, - 'topic_type': 'trending', - 'source_image': '', - 'is_english': not any('\uAC00' <= c <= '\uD7A3' for c in keyword), - 'sources': [], - } + loop = asyncio.get_event_loop() + try: + topic_data = await asyncio.wait_for( + loop.run_in_executor(None, _search_and_build_topic, keyword, corner), + timeout=15 + ) + except (asyncio.TimeoutError, Exception): + # 검색 실패 시 키워드만으로 저장 + if not corner: + corner = _guess_corner(keyword, keyword) + topic_data = { + 'topic': keyword, + 'description': f"{keyword}에 대한 최신 정보와 분석", + 'source': 'idea', + 'source_name': '직접 입력', + 'source_url': '', + 'published_at': datetime.now().strftime('%Y-%m-%d'), + 'corner': corner, + 'quality_score': 85, + 'search_demand_score': 9, + 'topic_type': 'trending', + 'source_image': '', + 'is_english': not any('\uAC00' <= c <= '\uD7A3' for c in keyword), + 'sources': [], + } # topics 폴더에 저장 topics_dir = DATA_DIR / 'topics' @@ -775,10 +781,15 @@ async def cmd_idea(update: Update, context: ContextTypes.DEFAULT_TYPE): all_files = sorted(topics_dir.glob(f'{today}_*.json')) idx = next((i for i, f in enumerate(all_files, 1) if f.name == filename), len(all_files)) + sources = topic_data.get('sources', []) + source_lines = [f" • {s.get('title', '')[:45]}" for s in sources[:3]] + sources_text = '\n'.join(source_lines) if source_lines else " (AI 자체 지식으로 작성)" + await update.message.reply_text( f"✅ 글감 등록! (#{idx})\n" f"주제: {topic_data.get('topic', '')[:60]}\n" f"카테고리: {topic_data.get('corner', '')}\n\n" + f"📰 참고 자료:\n{sources_text}\n\n" f"👉 /write {idx}" )