Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -59,31 +59,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
59 |
|
60 |
|
61 |
@tool
|
62 |
-
def get_weather(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
try:
|
64 |
-
|
65 |
-
response
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
condition_match = re.search(r'"wxPhrase":"(.*?)"', response.text)
|
73 |
-
|
74 |
-
if temp_match and condition_match:
|
75 |
-
temperature = f"{temp_match.group(1)}°F"
|
76 |
-
condition = condition_match.group(1)
|
77 |
-
return f"Current weather in {city}: {temperature}, {condition}"
|
78 |
-
|
79 |
-
return "Weather data not found."
|
80 |
-
|
81 |
-
except Exception as e:
|
82 |
-
return f"Error fetching weather: {str(e)}"
|
83 |
-
|
84 |
-
# Example usage
|
85 |
-
city_code = "San Francisco, CA"
|
86 |
-
print(get_weather(city_code))
|
87 |
|
88 |
|
89 |
@tool
|
|
|
59 |
|
60 |
|
61 |
@tool
|
62 |
+
def get_weather(location: str = "auto") -> str:
|
63 |
+
"""Fetches the current weather for a specified location without using an API key.
|
64 |
+
|
65 |
+
Args:
|
66 |
+
location: A string representing a valid city name (e.g., 'New York').
|
67 |
+
Defaults to 'auto' to detect the location automatically.
|
68 |
+
|
69 |
+
Returns:
|
70 |
+
A string describing the weather conditions.
|
71 |
+
"""
|
72 |
+
|
73 |
+
BASE_URL = f"https://wttr.in/{location}?format=%C+%t+%h"
|
74 |
+
|
75 |
try:
|
76 |
+
response = requests.get(BASE_URL)
|
77 |
+
response.raise_for_status()
|
78 |
+
|
79 |
+
weather_data = response.text.strip()
|
80 |
+
return f"Weather in {location}: {weather_data}"
|
81 |
+
|
82 |
+
except requests.exceptions.RequestException as e:
|
83 |
+
return f"Error fetching weather data: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
|
86 |
@tool
|