Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -183,21 +183,29 @@ def get_minutecast_forecast(lat, lon):
|
|
183 |
logger.error(f"Error in get_minutecast_forecast: {e}")
|
184 |
return None
|
185 |
|
186 |
-
def create_summary_card(
|
187 |
-
if not
|
188 |
return dbc.Card([
|
189 |
dbc.CardBody([
|
190 |
html.H4("Summary", className="card-title"),
|
191 |
html.P("No summary data available.")
|
192 |
])
|
193 |
], className="mb-4")
|
194 |
-
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
return dbc.Card([
|
197 |
dbc.CardBody([
|
198 |
html.H4("Summary", className="card-title"),
|
199 |
-
html.P(f"
|
200 |
-
html.P(f"
|
|
|
|
|
201 |
])
|
202 |
], className="mb-4")
|
203 |
|
@@ -209,6 +217,8 @@ def create_current_weather_card(current):
|
|
209 |
html.P("No weather data available.")
|
210 |
])
|
211 |
], className="mb-4")
|
|
|
|
|
212 |
return dbc.Card([
|
213 |
dbc.CardBody([
|
214 |
html.H4("Current Weather", className="card-title"),
|
@@ -217,6 +227,8 @@ def create_current_weather_card(current):
|
|
217 |
html.P(f"Feels Like: {current['RealFeelTemperature']['Imperial']['Value']}°F"),
|
218 |
html.P(f"Wind: {current['Wind']['Speed']['Imperial']['Value']} mph"),
|
219 |
html.P(f"Humidity: {current['RelativeHumidity']}%"),
|
|
|
|
|
220 |
])
|
221 |
], className="mb-4")
|
222 |
|
@@ -357,32 +369,6 @@ def create_environmental_indices_card(indices_dict):
|
|
357 |
])
|
358 |
], className="mb-4")
|
359 |
|
360 |
-
def create_minutecast_card(minutecast_data):
|
361 |
-
if not minutecast_data or not isinstance(minutecast_data, dict):
|
362 |
-
return dbc.Card([
|
363 |
-
dbc.CardBody([
|
364 |
-
html.H4("MinuteCast® Forecast", className="card-title"),
|
365 |
-
html.P("No MinuteCast® data available.")
|
366 |
-
])
|
367 |
-
], className="mb-4")
|
368 |
-
summary = minutecast_data.get("Summary", None)
|
369 |
-
phrase = summary.get("Phrase", "N/A") if summary else "N/A"
|
370 |
-
precipitation = summary.get("PrecipitationSummary", {}) if summary else {}
|
371 |
-
precip_type = precipitation.get("PrecipitationType", "N/A")
|
372 |
-
start_time = summary.get("StartTime", None)
|
373 |
-
end_time = summary.get("EndTime", None)
|
374 |
-
start_str = datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%SZ").strftime("%I:%M %p") if start_time else "N/A"
|
375 |
-
end_str = datetime.strptime(end_time, "%Y-%m-%dT%H:%M:%SZ").strftime("%I:%M %p") if end_time else "N/A"
|
376 |
-
return dbc.Card([
|
377 |
-
dbc.CardBody([
|
378 |
-
html.H4("MinuteCast® Forecast", className="card-title"),
|
379 |
-
html.P(f"Summary: {phrase}"),
|
380 |
-
html.P(f"Precipitation Type: {precip_type}"),
|
381 |
-
html.P(f"Start: {start_str}"),
|
382 |
-
html.P(f"End: {end_str}")
|
383 |
-
])
|
384 |
-
], className="mb-4")
|
385 |
-
|
386 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
387 |
server = app.server
|
388 |
|
@@ -492,12 +478,11 @@ def update_weather(location, session_data):
|
|
492 |
if current is None or forecast_5day is None:
|
493 |
raise ValueError("Failed to fetch weather data")
|
494 |
|
495 |
-
results["summary"] = create_summary_card(
|
496 |
results["current"] = create_current_weather_card(current)
|
497 |
results["indices"] = create_environmental_indices_card(indices_dict)
|
498 |
results["hourly12"] = create_hourly_12hour_card(hourly_12)
|
499 |
results["forecast"] = create_forecast_5day_card(forecast_5day)
|
500 |
-
results["minutecast"] = create_minutecast_card(minutecast)
|
501 |
save_session_data(session_id, "weather_results", results)
|
502 |
except Exception as e:
|
503 |
logger.error(f"Session {session_id} error: {str(e)}")
|
@@ -522,7 +507,6 @@ def update_weather(location, session_data):
|
|
522 |
weather_results.get("current", ""),
|
523 |
weather_results.get("indices", ""),
|
524 |
html.Div([
|
525 |
-
weather_results.get("minutecast", ""),
|
526 |
weather_results.get("hourly12", ""),
|
527 |
weather_results.get("forecast", "")
|
528 |
])
|
|
|
183 |
logger.error(f"Error in get_minutecast_forecast: {e}")
|
184 |
return None
|
185 |
|
186 |
+
def create_summary_card(minutecast_data):
|
187 |
+
if not minutecast_data or not isinstance(minutecast_data, dict):
|
188 |
return dbc.Card([
|
189 |
dbc.CardBody([
|
190 |
html.H4("Summary", className="card-title"),
|
191 |
html.P("No summary data available.")
|
192 |
])
|
193 |
], className="mb-4")
|
194 |
+
summary = minutecast_data.get("Summary", None)
|
195 |
+
phrase = summary.get("Phrase", "N/A") if summary else "N/A"
|
196 |
+
precipitation = summary.get("PrecipitationSummary", {}) if summary else {}
|
197 |
+
precip_type = precipitation.get("PrecipitationType", "N/A")
|
198 |
+
start_time = summary.get("StartTime", None)
|
199 |
+
end_time = summary.get("EndTime", None)
|
200 |
+
start_str = datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%SZ").strftime("%I:%M %p") if start_time else "N/A"
|
201 |
+
end_str = datetime.strptime(end_time, "%Y-%m-%dT%H:%M:%SZ").strftime("%I:%M %p") if end_time else "N/A"
|
202 |
return dbc.Card([
|
203 |
dbc.CardBody([
|
204 |
html.H4("Summary", className="card-title"),
|
205 |
+
html.P(f"Summary: {phrase}"),
|
206 |
+
html.P(f"Precipitation Type: {precip_type}"),
|
207 |
+
html.P(f"Start: {start_str}"),
|
208 |
+
html.P(f"End: {end_str}")
|
209 |
])
|
210 |
], className="mb-4")
|
211 |
|
|
|
217 |
html.P("No weather data available.")
|
218 |
])
|
219 |
], className="mb-4")
|
220 |
+
uv_index = current.get("UVIndex", "N/A")
|
221 |
+
uv_index_text = current.get("UVIndexText", "N/A")
|
222 |
return dbc.Card([
|
223 |
dbc.CardBody([
|
224 |
html.H4("Current Weather", className="card-title"),
|
|
|
227 |
html.P(f"Feels Like: {current['RealFeelTemperature']['Imperial']['Value']}°F"),
|
228 |
html.P(f"Wind: {current['Wind']['Speed']['Imperial']['Value']} mph"),
|
229 |
html.P(f"Humidity: {current['RelativeHumidity']}%"),
|
230 |
+
html.P(f"UV Index: {uv_index}"),
|
231 |
+
html.P(f"UV Index Text: {uv_index_text}")
|
232 |
])
|
233 |
], className="mb-4")
|
234 |
|
|
|
369 |
])
|
370 |
], className="mb-4")
|
371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
373 |
server = app.server
|
374 |
|
|
|
478 |
if current is None or forecast_5day is None:
|
479 |
raise ValueError("Failed to fetch weather data")
|
480 |
|
481 |
+
results["summary"] = create_summary_card(minutecast)
|
482 |
results["current"] = create_current_weather_card(current)
|
483 |
results["indices"] = create_environmental_indices_card(indices_dict)
|
484 |
results["hourly12"] = create_hourly_12hour_card(hourly_12)
|
485 |
results["forecast"] = create_forecast_5day_card(forecast_5day)
|
|
|
486 |
save_session_data(session_id, "weather_results", results)
|
487 |
except Exception as e:
|
488 |
logger.error(f"Session {session_id} error: {str(e)}")
|
|
|
507 |
weather_results.get("current", ""),
|
508 |
weather_results.get("indices", ""),
|
509 |
html.Div([
|
|
|
510 |
weather_results.get("hourly12", ""),
|
511 |
weather_results.get("forecast", "")
|
512 |
])
|