|
|
|
import yfinance as yf |
|
from newsapi import NewsApiClient |
|
from datetime import datetime, timedelta |
|
|
|
class YahooFinanceClient: |
|
@staticmethod |
|
def download_data(ticker, start_str=None, end_str=None, period="6mo"): |
|
if period: |
|
return yf.download(ticker, period=period, progress=False) |
|
else: |
|
return yf.download(ticker, start=start_str, end=end_str, progress=False) |
|
|
|
@staticmethod |
|
def get_company_info(ticker): |
|
company = yf.Ticker(ticker) |
|
return company.info |
|
|
|
class NewsAPIClient: |
|
def __init__(self, api_key): |
|
self.client = NewsApiClient(api_key=api_key) |
|
|
|
def get_news(self, shortName, days_back=15): |
|
from_date = (datetime.now() - timedelta(days=days_back)).strftime('%Y-%m-%d') |
|
return self.client.get_everything(q=shortName, from_param=from_date, language='en', sort_by='relevancy', page_size=20)['articles'] |
|
|
|
|