File size: 869 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
32
33
34
35
36
37
38
39
40
import finnhub
from streamlit import secrets

finhub_api = secrets["finhub_api"]

from datetime import datetime, timedelta

def get_finhub(ticker):

    finhub_list = []

    def get_yesterday(frmt='%Y-%m-%d', string=True):
        yesterday = datetime.now() - timedelta(days=1)
        if string:
            return yesterday.strftime(frmt)
        return yesterday
    from datetime import datetime

    def get_today(frmt='%Y-%m-%d'):
        today = datetime.now()
        return today.strftime(frmt)

    # Example usage:
    today = get_today()  # Output: '2024-02-04'

    # Example usage:
    yesterday = get_yesterday()  

    finnhub_client = finnhub.Client(api_key=f"{finhub_api}")



    data = finnhub_client.company_news(ticker, _from=yesterday, to=today)

    for article in data:
        finhub_list.append(article['headline'])

    return finhub_list