Initial commit for fixing broken code: - Fixed ETF_Analyzer page config issue - Updated ETF_Portfolio_Builder with improved error handling and data validation

This commit is contained in:
Pascal BIBEHE 2025-05-24 23:24:40 +00:00
parent f0ea40767c
commit 2687b63d3f
2 changed files with 812 additions and 3121 deletions

View File

@ -1,3 +1,11 @@
# Set page config first, before any other Streamlit commands
st.set_page_config(
page_title="ETF Analyzer",
page_icon="📊",
layout="wide",
initial_sidebar_state="expanded"
)
"""
ETF Analyzer - Comprehensive ETF Analysis Tool
@ -21,7 +29,46 @@ import time
from typing import Dict, List, Tuple, Any, Optional, Union
import sys
import yfinance as yf
from dotenv import load_dotenv
import logging
# Load environment variables
load_dotenv()
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# FMP API configuration
FMP_API_KEY = st.session_state.get('fmp_api_key', os.getenv('FMP_API_KEY', ''))
FMP_BASE_URL = "https://financialmodelingprep.com/api/v3"
def test_fmp_connection():
"""Test the FMP API connection and display status."""
try:
if not FMP_API_KEY:
return False, "No API key found"
session = get_fmp_session()
test_url = f"{FMP_BASE_URL}/profile/AAPL?apikey={FMP_API_KEY}"
response = session.get(test_url)
if response.status_code == 200:
data = response.json()
if data and isinstance(data, list) and len(data) > 0:
return True, "Connected"
return False, f"Error: {response.status_code}"
except Exception as e:
return False, f"Error: {str(e)}"
# Add FMP connection status to the navigation bar
st.sidebar.markdown("---")
st.sidebar.subheader("FMP API Status")
connection_status, message = test_fmp_connection()
if connection_status:
st.sidebar.success(f"✅ FMP API: {message}")
else:
st.sidebar.error(f"❌ FMP API: {message}")
# --- Constants and Settings ---
CACHE_DIR = Path("cache")

File diff suppressed because it is too large Load Diff