ZainebS commited on
Commit
00fc27d
·
verified ·
1 Parent(s): 7cd625d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -16,23 +16,32 @@ def get_weather(city:str,lat: float, lng:float)-> str:
16
  lat: city lattitude
17
  lng: city longitude
18
  """
19
- # city_coords = {
20
- # "New York": (40.7128, -74.0060),
21
- # "London": (51.5074, -0.1278),
22
- # "Tokyo": (35.6895, 139.6917),
23
- # }
24
-
25
- # if city not in city_coords:
26
- # return "City not found. Try New York, London, or Tokyo."
27
-
28
- # lat, lon = city_coords[city]
 
 
 
 
 
 
 
 
 
29
  url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lng}&current_weather=true"
30
 
31
  response = requests.get(url)
32
  if response.status_code == 200:
33
  data = response.json()
34
  weather = data["current_weather"]
35
- return f"The weather in {city} is {weather['temperature']}°C with {weather['weathercode']}."
36
  else:
37
  return "Error fetching weather data."
38
 
 
16
  lat: city lattitude
17
  lng: city longitude
18
  """
19
+ # Map weather codes to descriptions
20
+ weather_descriptions = {
21
+ 0: "Clear sky",
22
+ 1: "Mainly clear",
23
+ 2: "Partly cloudy",
24
+ 3: "Overcast",
25
+ 45: "Foggy",
26
+ 48: "Depositing rime fog",
27
+ 51: "Light drizzle",
28
+ 53: "Moderate drizzle",
29
+ 55: "Dense drizzle",
30
+ 61: "Slight rain",
31
+ 63: "Moderate rain",
32
+ 65: "Heavy rain",
33
+ 80: "Light rain showers",
34
+ 81: "Moderate rain showers",
35
+ 82: "Heavy rain showers",
36
+ 95: "Thunderstorm",
37
+ }
38
  url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lng}&current_weather=true"
39
 
40
  response = requests.get(url)
41
  if response.status_code == 200:
42
  data = response.json()
43
  weather = data["current_weather"]
44
+ return f"The weather in {city} is {weather['temperature']}°C - weather_description[{weather['weathercode']}]."
45
  else:
46
  return "Error fetching weather data."
47