Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lng}¤t_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
|
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}¤t_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 |
|