generated from streamlit/gdp-dashboard-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnews.py
More file actions
36 lines (29 loc) · 1.09 KB
/
news.py
File metadata and controls
36 lines (29 loc) · 1.09 KB
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
import yfinance as yf
import streamlit as st
import logging
logging.basicConfig(level=logging.INFO, filename='app.log', filemode='a', format='%(asctime)s - %(levelname)s - %(message)s')
@st.cache_data
def get_news(ticker_symbol):
"""
Fetches news for a given stock ticker.
"""
logging.info(f"Fetching news for {ticker_symbol}")
ticker = yf.Ticker(ticker_symbol)
company_news = ticker.news
if not company_news:
logging.info(f"No news found for {ticker_symbol}")
return []
news_list = []
for article in company_news:
content = article.get('content', {})
headline = content.get('title', 'N/A - No Title Found')
canonical_url = content.get('canonicalUrl', {})
link = canonical_url.get('url', 'N/A - No Link Found')
publisher = article.get('publisher', 'N/A - No Publisher')
logging.info(f"Fetched headline for {ticker_symbol}: {headline}")
news_list.append({
'headline': headline,
'link': link,
'publisher': publisher
})
return news_list