Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,27 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
|
| 5 |
-
st.title("
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Hardcode ticker for simplicity (AAPL)
|
| 8 |
ticker = "AAPL"
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# Use yfinance's Ticker with default session management
|
| 17 |
-
stock = yf.Ticker(ticker)
|
| 18 |
-
start_date = datetime.now() - timedelta(days=look_back_days)
|
| 19 |
-
end_date = datetime.now()
|
| 20 |
-
hist_data = stock.history(start=start_date, end=end_date, interval="1d")
|
| 21 |
-
|
| 22 |
-
if not hist_data.empty:
|
| 23 |
-
st.success(f"Yahoo Finance is available! Data found for {ticker}:")
|
| 24 |
-
st.write(hist_data)
|
| 25 |
-
return True
|
| 26 |
-
else:
|
| 27 |
-
st.error(f"No data found for {ticker}. Yahoo Finance may be unavailable or rate-limited.")
|
| 28 |
-
return False
|
| 29 |
-
except Exception as e:
|
| 30 |
-
st.error(f"Error checking Yahoo Finance for {ticker}: {str(e)}")
|
| 31 |
-
st.write(f"Yahoo Finance is not responding. Check finance.yahoo.com/quote/{ticker} or search X for outages.")
|
| 32 |
-
return False
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
+
st.title("GuruFocus Stock Data App")
|
| 6 |
+
|
| 7 |
+
# Your GuruFocus API token (replace with your actual token)
|
| 8 |
+
api_token = "4ec46abd2df12391af4906d0cbbd69ac:68d2f6ba6503c4e30503145a97bc9dec" # Obtain from GuruFocus account
|
| 9 |
|
| 10 |
# Hardcode ticker for simplicity (AAPL)
|
| 11 |
ticker = "AAPL"
|
| 12 |
|
| 13 |
+
# Fetch stock summary from GuruFocus API
|
| 14 |
+
url = f"https://api.gurufocus.com/public/user/{api_token}/stock/{ticker}/summary"
|
| 15 |
+
try:
|
| 16 |
+
response = requests.get(url)
|
| 17 |
+
response.raise_for_status() # Raise an exception for HTTP errors
|
| 18 |
+
data = response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Display stock data
|
| 21 |
+
st.write("Stock Summary for", ticker)
|
| 22 |
+
st.json(data) # Display raw JSON for simplicity (expand with specific fields later)
|
| 23 |
+
except requests.exceptions.HTTPError as e:
|
| 24 |
+
st.error(f"Error fetching data: {str(e)}")
|
| 25 |
+
st.write("Check your API token, ticker, or GuruFocus API status.")
|
| 26 |
+
except Exception as e:
|
| 27 |
+
st.error(f"Unexpected error: {str(e)}")
|