Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -129,6 +129,14 @@ def main():
|
|
| 129 |
if data and 'data' in data:
|
| 130 |
current_weather_data = data['data']
|
| 131 |
current = current_weather_data[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
st.subheader(f"Weather at {lat}, {lon} on {datetime_input}")
|
| 134 |
|
|
@@ -146,8 +154,9 @@ def main():
|
|
| 146 |
st.metric("Wind Direction", f"{current['wind_deg']}°")
|
| 147 |
st.metric("UV Index", f"{current['uvi']}")
|
| 148 |
st.metric("Cloud Cover", f"{current.get('clouds', 'N/A')}%")
|
| 149 |
-
|
| 150 |
-
st.
|
|
|
|
| 151 |
|
| 152 |
# Weather description
|
| 153 |
if 'weather' in current and current['weather']:
|
|
|
|
| 129 |
if data and 'data' in data:
|
| 130 |
current_weather_data = data['data']
|
| 131 |
current = current_weather_data[0]
|
| 132 |
+
# Convert and format sunrise and sunset
|
| 133 |
+
timezone = data.get('timezone', 'UTC') # Get timezone or default to UTC
|
| 134 |
+
tz = pytz.timezone(timezone)
|
| 135 |
+
|
| 136 |
+
sunrise_time = datetime.fromtimestamp(current['sunrise'], tz).strftime('%Y-%m-%d %H:%M:%S')
|
| 137 |
+
sunset_time = datetime.fromtimestamp(current['sunset'], tz).strftime('%Y-%m-%d %H:%M:%S')
|
| 138 |
+
|
| 139 |
+
|
| 140 |
|
| 141 |
st.subheader(f"Weather at {lat}, {lon} on {datetime_input}")
|
| 142 |
|
|
|
|
| 154 |
st.metric("Wind Direction", f"{current['wind_deg']}°")
|
| 155 |
st.metric("UV Index", f"{current['uvi']}")
|
| 156 |
st.metric("Cloud Cover", f"{current.get('clouds', 'N/A')}%")
|
| 157 |
+
# Display sunrise and sunset times
|
| 158 |
+
st.write(f"**Sunrise:** {sunrise_time}")
|
| 159 |
+
st.write(f"**Sunset:** {sunset_time}")
|
| 160 |
|
| 161 |
# Weather description
|
| 162 |
if 'weather' in current and current['weather']:
|