Pijush2023 commited on
Commit
ac15860
·
verified ·
1 Parent(s): 01530f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -2
app.py CHANGED
@@ -146,6 +146,72 @@ def fetch_local_events():
146
  else:
147
  return "<p>Failed to fetch local events</p>"
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  def fetch_local_weather():
150
  try:
151
  api_key = os.environ['WEATHER_API']
@@ -156,10 +222,12 @@ def fetch_local_weather():
156
 
157
  current_conditions = jsonData.get("currentConditions", {})
158
  temp_celsius = current_conditions.get("temp", "N/A")
 
159
  if temp_celsius != "N/A":
160
- temp_fahrenheit = (temp_celsius * 9/5) + 32
161
  else:
162
  temp_fahrenheit = "N/A"
 
163
  condition = current_conditions.get("conditions", "N/A")
164
  humidity = current_conditions.get("humidity", "N/A")
165
 
@@ -212,7 +280,6 @@ def fetch_local_weather():
212
  return weather_html
213
  except requests.exceptions.RequestException as e:
214
  return f"<p>Failed to fetch local weather: {e}</p>"
215
-
216
  def get_weather_icon(condition):
217
  condition_map = {
218
  "Clear": "c01d",
 
146
  else:
147
  return "<p>Failed to fetch local events</p>"
148
 
149
+ # def fetch_local_weather():
150
+ # try:
151
+ # api_key = os.environ['WEATHER_API']
152
+ # url = f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/omaha?unitGroup=metric&include=events%2Calerts%2Chours%2Cdays%2Ccurrent&key={api_key}'
153
+ # response = requests.get(url)
154
+ # response.raise_for_status()
155
+ # jsonData = response.json()
156
+
157
+ # current_conditions = jsonData.get("currentConditions", {})
158
+ # temp_celsius = current_conditions.get("temp", "N/A")
159
+ # if temp_celsius != "N/A":
160
+ # temp_fahrenheit = (temp_celsius * 9/5) + 32
161
+ # else:
162
+ # temp_fahrenheit = "N/A"
163
+ # condition = current_conditions.get("conditions", "N/A")
164
+ # humidity = current_conditions.get("humidity", "N/A")
165
+
166
+ # weather_html = f"""
167
+ # <div class="weather-theme">
168
+ # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Weather</h2>
169
+ # <div class="weather-content">
170
+ # <div class="weather-icon">
171
+ # <img src="https://www.weatherbit.io/static/img/icons/{get_weather_icon(condition)}.png" alt="{condition}" style="width: 100px; height: 100px;">
172
+ # </div>
173
+ # <div class="weather-details">
174
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Temperature: {temp_fahrenheit}°F</p>
175
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Condition: {condition}</p>
176
+ # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Humidity: {humidity}%</p>
177
+ # </div>
178
+ # </div>
179
+ # </div>
180
+ # <style>
181
+ # .weather-theme {{
182
+ # animation: backgroundAnimation 10s infinite alternate;
183
+ # border: 1px solid #ddd;
184
+ # border-radius: 10px;
185
+ # padding: 10px;
186
+ # margin-bottom: 15px;
187
+ # background: linear-gradient(45deg, #ffcc33, #ff6666, #ffcc33, #ff6666);
188
+ # background-size: 400% 400%;
189
+ # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
190
+ # transition: box-shadow 0.3s ease, background-color 0.3s ease;
191
+ # }}
192
+ # .weather-theme:hover {{
193
+ # box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
194
+ # background-position: 100% 100%;
195
+ # }}
196
+ # @keyframes backgroundAnimation {{
197
+ # 0% {{ background-position: 0% 50%; }}
198
+ # 100% {{ background-position: 100% 50%; }}
199
+ # }}
200
+ # .weather-content {{
201
+ # display: flex;
202
+ # align-items: center;
203
+ # }}
204
+ # .weather-icon {{
205
+ # flex: 1;
206
+ # }}
207
+ # .weather-details {{
208
+ # flex: 3;
209
+ # }}
210
+ # </style>
211
+ # """
212
+ # return weather_html
213
+ # except requests.exceptions.RequestException as e:
214
+ # return f"<p>Failed to fetch local weather: {e}</p>"
215
  def fetch_local_weather():
216
  try:
217
  api_key = os.environ['WEATHER_API']
 
222
 
223
  current_conditions = jsonData.get("currentConditions", {})
224
  temp_celsius = current_conditions.get("temp", "N/A")
225
+
226
  if temp_celsius != "N/A":
227
+ temp_fahrenheit = int((temp_celsius * 9/5) + 32)
228
  else:
229
  temp_fahrenheit = "N/A"
230
+
231
  condition = current_conditions.get("conditions", "N/A")
232
  humidity = current_conditions.get("humidity", "N/A")
233
 
 
280
  return weather_html
281
  except requests.exceptions.RequestException as e:
282
  return f"<p>Failed to fetch local weather: {e}</p>"
 
283
  def get_weather_icon(condition):
284
  condition_map = {
285
  "Clear": "c01d",