antfraia commited on
Commit
b4497ef
·
1 Parent(s): 1875498

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -9,7 +9,21 @@ def kelvin_to_celsius(temp_kelvin):
9
  return temp_kelvin - 273.15
10
 
11
  def get_weather(city_name, api_key):
12
- # ... [same as your previous code] ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  def summarize_text(text):
15
  """Summarize the provided text using OpenAI."""
 
9
  return temp_kelvin - 273.15
10
 
11
  def get_weather(city_name, api_key):
12
+ base_url = "http://api.openweathermap.org/data/2.5/weather?"
13
+ complete_url = base_url + "q=" + city_name + "&appid=" + api_key
14
+ response = requests.get(complete_url)
15
+ data = response.json()
16
+
17
+ if data.get("cod") == 200:
18
+ main_data = data.get("main", {})
19
+ weather_data = data.get("weather", [{}])[0]
20
+ temperature = kelvin_to_celsius(main_data.get("temp", 0))
21
+ pressure = main_data.get("pressure", "N/A")
22
+ humidity = main_data.get("humidity", "N/A")
23
+ weather_description = weather_data.get("description", "N/A")
24
+ return temperature, pressure, humidity, weather_description
25
+ else:
26
+ return None
27
 
28
  def summarize_text(text):
29
  """Summarize the provided text using OpenAI."""