aromidvar1355 commited on
Commit
bfa5f9b
·
verified ·
1 Parent(s): 3577fb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
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
- st.metric("Sunrise", f"{current.get('sunrise', 'N/A')}%")
150
- st.metric("Sunset", f"{current.get('sunset', 'N/A')}%")
 
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']: