TNK21 commited on
Commit
906c5ec
·
verified ·
1 Parent(s): 9f39c86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -33,6 +33,36 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def get_weather_report(city: str) -> str:
38
+ """Fetches the current weather report for a given city using Open-Meteo API.
39
+ Args:
40
+ city: Name of the city (e.g., 'Paris', 'New York').
41
+ """
42
+ try:
43
+ geocode_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1"
44
+ geo_response = requests.get(geocode_url).json()
45
+
46
+ if not geo_response.get("results"):
47
+ return f"Could not find coordinates for {city}."
48
+
49
+ lat = geo_response["results"][0]["latitude"]
50
+ lon = geo_response["results"][0]["longitude"]
51
+
52
+ weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true"
53
+ weather_response = requests.get(weather_url).json()
54
+ weather = weather_response.get("current_weather", {})
55
+
56
+ if not weather:
57
+ return f"No weather data available for {city}."
58
+
59
+ temperature = weather.get("temperature")
60
+ windspeed = weather.get("windspeed")
61
+ weather_desc = f"🌤️ Weather in {city.title()}: {temperature}°C with wind speed of {windspeed} km/h."
62
+ return weather_desc
63
+
64
+ except Exception as e:
65
+ return f"An error occurred while fetching weather data: {str(e)}"
66
 
67
  final_answer = FinalAnswerTool()
68