|
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 |
|
|
|
|
|
|