fix(agent-office): get_running_loop + pytrends timeout + UA 수정
- asyncio.get_event_loop() → asyncio.get_running_loop() (python 3.10+ 권장) - TrendReq에 timeout=(5, 15) 추가 (connect, read timeout) - User-Agent에서 'bot' 제거: 표준 Chrome UA로 변경 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -82,7 +82,7 @@ async def fetch_google_trends(keywords: List[str], countries: List[str]) -> List
|
||||
|
||||
def _sync_fetch(kw: str) -> List[Dict[str, Any]]:
|
||||
try:
|
||||
pt = TrendReq(hl="en-US", tz=0)
|
||||
pt = TrendReq(hl="en-US", tz=0, timeout=(5, 15))
|
||||
pt.build_payload([kw], timeframe="now 7-d")
|
||||
df = pt.interest_over_time()
|
||||
if df.empty or kw not in df.columns:
|
||||
@@ -96,7 +96,7 @@ async def fetch_google_trends(keywords: List[str], countries: List[str]) -> List
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = asyncio.get_running_loop()
|
||||
results = []
|
||||
for kw in keywords[:5]:
|
||||
rows = await loop.run_in_executor(None, _sync_fetch, kw)
|
||||
@@ -109,7 +109,7 @@ async def fetch_billboard_top20() -> List[Dict[str, Any]]:
|
||||
"""Billboard Hot 100 스크래핑 — 상위 20위."""
|
||||
async with httpx.AsyncClient(
|
||||
timeout=10.0,
|
||||
headers={"User-Agent": "Mozilla/5.0 (compatible; music-research-bot/1.0)"},
|
||||
headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"},
|
||||
follow_redirects=True,
|
||||
) as client:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user