Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -56,24 +56,37 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
56 |
except Exception as e:
|
57 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
58 |
|
|
|
59 |
@tool
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
-
return (f"The current Weather in {location} is: {conditions.capitalize()},"
|
75 |
-
f"Temperature: {temperature}°C, Humidity: {humidity}%")
|
76 |
-
|
77 |
|
78 |
@tool
|
79 |
def getMarsWeather() -> str:
|
|
|
56 |
except Exception as e:
|
57 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
58 |
|
59 |
+
|
60 |
@tool
|
61 |
+
import requests
|
62 |
+
import re
|
63 |
+
|
64 |
+
def fetch_weather(city):
|
65 |
+
try:
|
66 |
+
url = f"https://www.weather.com/weather/today/l/{city}"
|
67 |
+
response = requests.get(url)
|
68 |
+
|
69 |
+
if response.status_code != 200:
|
70 |
+
return "Failed to fetch weather data."
|
71 |
+
|
72 |
+
# Extract temperature and condition using regex
|
73 |
+
temp_match = re.search(r'"temperature":(\d+)', response.text)
|
74 |
+
condition_match = re.search(r'"wxPhrase":"(.*?)"', response.text)
|
75 |
+
|
76 |
+
if temp_match and condition_match:
|
77 |
+
temperature = f"{temp_match.group(1)}°C"
|
78 |
+
condition = condition_match.group(1)
|
79 |
+
return f"Current weather in {city}: {temperature}, {condition}"
|
80 |
+
|
81 |
+
return "Weather data not found."
|
82 |
+
|
83 |
+
except Exception as e:
|
84 |
+
return f"Error fetching weather: {str(e)}"
|
85 |
+
|
86 |
+
# Example usage
|
87 |
+
city_code = "San Francisco, CA"
|
88 |
+
print(fetch_weather(city_code))
|
89 |
|
|
|
|
|
|
|
90 |
|
91 |
@tool
|
92 |
def getMarsWeather() -> str:
|