File size: 626 Bytes
415516b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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