cwadayi commited on
Commit
79a1bad
·
verified ·
1 Parent(s): 0cbc42d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +11 -3
src/streamlit_app.py CHANGED
@@ -60,8 +60,16 @@ if search_button:
60
  if df is not None and not df.empty:
61
  st.success(f"Found {len(df)} earthquakes matching your criteria.")
62
 
63
- # CORRECTED LINE: Use 'event_time' from the API and assign it to a new 'time' column.
64
- df['time'] = pd.to_datetime(df['event_time'])
 
 
 
 
 
 
 
 
65
 
66
  df['magnitude'] = df['mag'].astype(float)
67
  df['depth'] = df['depth'].astype(float)
@@ -86,7 +94,7 @@ if search_button:
86
  hover_data={
87
  'latitude': ':.2f',
88
  'longitude': ':.2f',
89
- 'time': True, # This now works because we created the 'time' column
90
  'magnitude': ':.2f',
91
  'depth': ':.2f km'
92
  },
 
60
  if df is not None and not df.empty:
61
  st.success(f"Found {len(df)} earthquakes matching your criteria.")
62
 
63
+ # --- ROBUST FIX IS HERE ---
64
+ # The API is inconsistent. Check for 'event_time', otherwise fall back to 'time'.
65
+ if 'event_time' in df.columns:
66
+ df['time'] = pd.to_datetime(df['event_time'])
67
+ elif 'time' in df.columns:
68
+ df['time'] = pd.to_datetime(df['time'])
69
+ else:
70
+ # If neither key is found, show an error and stop execution.
71
+ st.error("Data format error: Could not find a valid time column in the API response.")
72
+ st.stop()
73
 
74
  df['magnitude'] = df['mag'].astype(float)
75
  df['depth'] = df['depth'].astype(float)
 
94
  hover_data={
95
  'latitude': ':.2f',
96
  'longitude': ':.2f',
97
+ 'time': True,
98
  'magnitude': ':.2f',
99
  'depth': ':.2f km'
100
  },