def get_topk_trending_news(
    limit: int = 10, extract_content: bool = False
) -> List[Dict[str, Any]]:
    """Returns top Kk trending news from seekingalpha."""
    articles = []
    URL = "https://seekingalpha.com/news/trending_news"
    response = request(URL)
    if response.status_code == 200:
        for item in response.json():
            article_url = item["uri"]
            if not article_url.startswith("/news/"):
                continue

            article_id = article_url.split("/")[2].split("-")[0]

            content = ""
            if extract_content:
                article_url = f"https://seekingalpha.com/api/v3/news/{article_id}"
                article_response = request(article_url)
                jdata = article_response.json()
                try:
                    content = jdata["data"]["attributes"]["content"].replace(
                        "</li>", "</li>\n"
                    )
                    content = BeautifulSoup(content, features="html.parser").get_text()
                except Exception as e:
                    print(f"Unable to extract content for: {article_url}")

            articles.append(
                {
                    "title": item["title"],
                    "publishedAt": item["publish_on"][: item["publish_on"].rfind(".")],
                    "url": "https://seekingalpha.com" + article_url,
                    "id": article_id,
                    "content": content,
                }
            )

            if len(articles) > limit:
                break

    return articles[:limit]
Returns top Kk trending news from seekingalpha.
llama-index-integrations/tools/llama-index-tools-finance/llama_index/tools/finance/news.py