Crypto-Analyst / news_tools.py
menikev's picture
Upload 3 files
e8a9836 verified
raw
history blame contribute delete
659 Bytes
from langchain.tools import tool
import requests
class NewsTools:
@tool("Search Crypto News")
def search_crypto_news(query):
"""Searches for cryptocurrency news articles based on a given query."""
url = f"https://cryptonews-api.com/api/v1/category?section=general&items=10&token=YOUR_API_KEY&q={query}"
response = requests.get(url)
if response.status_code == 200:
articles = response.json()['data']
return [{'title': article['title'], 'source': article['source_name'], 'url': article['news_url']} for article in articles]
else:
return "Error fetching news data"