3be7886bfe
- yahooquery, ta 라이브러리 활용
26 lines
737 B
Python
26 lines
737 B
Python
from langchain_community.utilities import GoogleSerperAPIWrapper
|
|
|
|
from backend.schemas.news_schemas import NewsItem
|
|
|
|
|
|
async def get_news(company_name: str):
|
|
"""
|
|
구글 뉴스 검색 후
|
|
title, snippet, url, source, date 추출
|
|
"""
|
|
search = GoogleSerperAPIWrapper(type="news")
|
|
results = await search.results(f"{company_name} stock news")
|
|
news_list = []
|
|
|
|
for item in results['news'][:10]:
|
|
news_list.append(
|
|
NewsItem(
|
|
title=item.get("title", ""),
|
|
snippet=item.get("snippet", ""),
|
|
url=item.get("link", ""),
|
|
source=item.get("source", ""),
|
|
date=item.get("date", "")
|
|
)
|
|
)
|
|
|
|
return news_list |