Update src/streamlit_app.py
Browse files- 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 |
-
#
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|
| 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 |
},
|