antfraia commited on
Commit
1a3d149
·
1 Parent(s): 58cb96e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -5,7 +5,7 @@ from datetime import datetime, timedelta
5
  API_KEY = "91b23cab82ee530b2052c8757e343b0d"
6
 
7
  def kelvin_to_celsius(temp_kelvin):
8
- return temp_kelvin - 273.15
9
 
10
  def get_weather(city_name):
11
  base_url = "http://api.openweathermap.org/data/2.5/weather?"
@@ -19,18 +19,21 @@ def get_weather(city_name):
19
  temperature = kelvin_to_celsius(main_data.get("temp", 0))
20
  weather_description = weather_data.get("description", "N/A")
21
  timezone = data.get("timezone", 0)
22
- local_time = (datetime.utcnow() + timedelta(seconds=timezone)).strftime('%H:%M:%S')
23
  return temperature, weather_description, local_time
24
  else:
25
  return None
26
 
27
  def summarize_weather(city1, city2):
 
 
 
28
  weather1 = get_weather(city1)
29
  weather2 = get_weather(city2)
30
 
31
  if weather1 and weather2:
32
- summary = (f"In {city1} it's {weather1[2]} and {weather1[1]} with {weather1[0]:.2f}°C, "
33
- f"while in {city2} it's {weather2[2]} and {weather2[1]} with {weather2[0]:.2f}°C.")
34
  return summary
35
  else:
36
  return "Error fetching weather data for one or both cities."
 
5
  API_KEY = "91b23cab82ee530b2052c8757e343b0d"
6
 
7
  def kelvin_to_celsius(temp_kelvin):
8
+ return int(temp_kelvin - 273.15) # Convert to int to remove decimals
9
 
10
  def get_weather(city_name):
11
  base_url = "http://api.openweathermap.org/data/2.5/weather?"
 
19
  temperature = kelvin_to_celsius(main_data.get("temp", 0))
20
  weather_description = weather_data.get("description", "N/A")
21
  timezone = data.get("timezone", 0)
22
+ local_time = (datetime.utcnow() + timedelta(seconds=timezone)).strftime('%H:%M') # Removed seconds
23
  return temperature, weather_description, local_time
24
  else:
25
  return None
26
 
27
  def summarize_weather(city1, city2):
28
+ city1 = city1.capitalize()
29
+ city2 = city2.capitalize()
30
+
31
  weather1 = get_weather(city1)
32
  weather2 = get_weather(city2)
33
 
34
  if weather1 and weather2:
35
+ summary = (f"In {city1} it's {weather1[2]} and {weather1[1]} with {weather1[0]}°C, "
36
+ f"while in {city2} it's {weather2[2]} and {weather2[1]} with {weather2[0]}°C.")
37
  return summary
38
  else:
39
  return "Error fetching weather data for one or both cities."