khaled06 commited on
Commit
610f1a0
·
verified ·
1 Parent(s): fb380d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -34,21 +34,27 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
  @tool
37
- def get_weather_api(city : str) -> str:
38
- """A tool that get the current weather.
39
- Args:
40
- city: A string that repesents a city name
 
41
  """
42
  api_key = 'ff33163dc424d6430b66535cb02dda7d'
43
-
44
- response = requests.get(url)
45
- data = response.json()
46
-
47
- if 'current' in data and 'weather_descriptions' in data['current']:
48
- temp = data['current']['weather_descriptions'][0]
49
- return f"The current weather in {city} is {temp}."
50
- else:
51
- return f"Could not retrieve weather data for {city}."
 
 
 
 
 
52
 
53
 
54
 
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
  @tool
37
+ def get_weather_api(city: str) -> str:
38
+ """A tool that gets the current weather.
39
+
40
+ Args:
41
+ city (str): A string that represents a city name.
42
  """
43
  api_key = 'ff33163dc424d6430b66535cb02dda7d'
44
+ url = f"http://api.weatherstack.com/current?access_key={api_key}&query={city}"
45
+
46
+ try:
47
+ response = requests.get(url)
48
+ data = response.json()
49
+
50
+ if 'current' in data and 'weather_descriptions' in data['current']:
51
+ temp = data['current']['weather_descriptions'][0]
52
+ return f"The current weather in {city} is {temp}."
53
+ else:
54
+ return f"Could not retrieve weather data for {city}."
55
+ except Exception as e:
56
+ return f"Error retrieving weather data: {str(e)}"
57
+
58
 
59
 
60