Spaces:
Runtime error
Runtime error
Create weather.py
Browse files- weather.py +11 -0
weather.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
def get_weather(city):
|
| 4 |
+
"""Fetch real-time weather from wttr.in"""
|
| 5 |
+
url = f"https://wttr.in/{city}?format=%C+%t"
|
| 6 |
+
try:
|
| 7 |
+
response = requests.get(url).text
|
| 8 |
+
return f"Hali ya hewa katika {city}: {response}"
|
| 9 |
+
except Exception:
|
| 10 |
+
return "Samahani, siwezi kupata hali ya hewa kwa sasa."
|
| 11 |
+
|