Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,24 +17,21 @@ def get_weather(location:str,)-> dict: #it's import to specify the return type
|
|
17 |
location: A string representing location (Eg. London)
|
18 |
"""
|
19 |
api_key = os.getenv("openweatherapikey")
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
data = response.json()
|
30 |
-
return {
|
31 |
"location": data["name"],
|
32 |
"temperature": data["main"]["temp"],
|
33 |
"weather": data["weather"][0]["description"]
|
34 |
}
|
35 |
else:
|
36 |
return {"error": "Could not fetch weather data"}
|
37 |
-
|
38 |
@tool
|
39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
40 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
17 |
location: A string representing location (Eg. London)
|
18 |
"""
|
19 |
api_key = os.getenv("openweatherapikey")
|
20 |
+
url = f'http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}'
|
21 |
+
|
22 |
+
response = requests.get(url)
|
23 |
+
|
24 |
+
if response.status_code == 200:
|
25 |
+
data = response.json()
|
26 |
+
temp = data['main']['temp']
|
27 |
+
desc = data['weather'][0]['description']
|
28 |
+
return {
|
|
|
|
|
29 |
"location": data["name"],
|
30 |
"temperature": data["main"]["temp"],
|
31 |
"weather": data["weather"][0]["description"]
|
32 |
}
|
33 |
else:
|
34 |
return {"error": "Could not fetch weather data"}
|
|
|
35 |
@tool
|
36 |
def get_current_time_in_timezone(timezone: str) -> str:
|
37 |
"""A tool that fetches the current local time in a specified timezone.
|