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]]:
|
def _sync_fetch(kw: str) -> List[Dict[str, Any]]:
|
||||||
try:
|
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")
|
pt.build_payload([kw], timeframe="now 7-d")
|
||||||
df = pt.interest_over_time()
|
df = pt.interest_over_time()
|
||||||
if df.empty or kw not in df.columns:
|
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:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_running_loop()
|
||||||
results = []
|
results = []
|
||||||
for kw in keywords[:5]:
|
for kw in keywords[:5]:
|
||||||
rows = await loop.run_in_executor(None, _sync_fetch, kw)
|
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위."""
|
"""Billboard Hot 100 스크래핑 — 상위 20위."""
|
||||||
async with httpx.AsyncClient(
|
async with httpx.AsyncClient(
|
||||||
timeout=10.0,
|
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,
|
follow_redirects=True,
|
||||||
) as client:
|
) as client:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user