mokout commited on
Commit
2ee6a16
·
verified ·
1 Parent(s): 54cc20d

error handing update

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -115,20 +115,27 @@ def calculate_kmeans_clusters(data, n_days, num_clusters):
115
  # Run the analysis
116
  if st.sidebar.button('Run Analysis'):
117
  # Fetch data
 
118
  try:
119
- data = yf.download(ticker, start=start_date, end=end_date, auto_adjust=False)
120
- if data.empty:
 
 
121
  st.error(f"No data found for ticker: {ticker}. Please check the symbol and date range.")
 
 
122
  else:
123
  # Flatten if multi-indexed columns
124
  if isinstance(data.columns, pd.MultiIndex):
125
  data.columns = data.columns.get_level_values(0)
126
- st.success("Data download successful!")
127
  st.dataframe(data.head())
128
  except Exception as e:
129
  st.error(f"Error downloading data: {e}")
 
 
130
 
131
- if not data.empty:
132
  # Calculate Pivot Points
133
  try:
134
  df_pivot = calculate_pivot_points(data.copy(), window_period)
@@ -346,6 +353,16 @@ if st.sidebar.button('Run Analysis'):
346
  else:
347
  st.write("No data found for the given ticker and date range.")
348
 
 
 
 
 
 
 
 
 
 
 
349
  hide_streamlit_style = """
350
  <style>
351
  #MainMenu {visibility: hidden;}
 
115
  # Run the analysis
116
  if st.sidebar.button('Run Analysis'):
117
  # Fetch data
118
+ data = None
119
  try:
120
+ with st.spinner(f"Downloading data for {ticker}..."):
121
+ data = yf.download(ticker, start=start_date, end=end_date, auto_adjust=False, progress=False)
122
+
123
+ if data is None or data.empty:
124
  st.error(f"No data found for ticker: {ticker}. Please check the symbol and date range.")
125
+ st.info("Try using a different ticker symbol or adjusting the date range.")
126
+ data = None
127
  else:
128
  # Flatten if multi-indexed columns
129
  if isinstance(data.columns, pd.MultiIndex):
130
  data.columns = data.columns.get_level_values(0)
131
+ st.success(f"Data download successful! Retrieved {len(data)} data points.")
132
  st.dataframe(data.head())
133
  except Exception as e:
134
  st.error(f"Error downloading data: {e}")
135
+ st.info("This could be due to network issues or an invalid ticker symbol.")
136
+ data = None
137
 
138
+ if data is not None and not data.empty:
139
  # Calculate Pivot Points
140
  try:
141
  df_pivot = calculate_pivot_points(data.copy(), window_period)
 
353
  else:
354
  st.write("No data found for the given ticker and date range.")
355
 
356
+ else:
357
+ st.info("👆 Click 'Run Analysis' in the sidebar to start analyzing stock data!")
358
+ st.markdown("""
359
+ ### Getting Started:
360
+ 1. Enter a stock ticker (e.g., AAPL, GOOGL, TSLA) or crypto pair (e.g., BTC-USD)
361
+ 2. Set your desired date range
362
+ 3. Adjust the analysis parameters if needed
363
+ 4. Click 'Run Analysis' to generate the charts and insights
364
+ """)
365
+
366
  hide_streamlit_style = """
367
  <style>
368
  #MainMenu {visibility: hidden;}