financial_news_fast_inference / newsapi_caller.py
Andreagus's picture
Update newsapi_caller.py
5b08228 verified
raw history blame
No virus
626 Bytes
import datetime
import requests
from streamlit import secrets
news_api = secrets["news_api"]
def get_newsapi(company):
newsapi_list = []
def get_today(frmt='%Y-%m-%d'):
today = datetime.date.today()
return today.strftime(frmt)
today = get_today()
url = f"https://newsapi.org/v2/everything?q={company}&from={today}&sortBy=popularity&apiKey={news_api}"
headers = {"accept": "application/json"}
r = requests.request("GET", url, headers=headers)
data = r.json()
for article in data['articles']:
newsapi_list.append(article['title'])
return newsapi_list