aniketkno commited on
Commit
e6a3f39
·
verified ·
1 Parent(s): c26292a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -34,7 +34,7 @@ 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_forecast(city_name):
38
  """A tool that fetches the current weather of a specified city.
39
  Args:
40
  city_name: A string representing a valid city (e.g., 'Bangalore').
@@ -55,8 +55,13 @@ def get_weather_forecast(city_name):
55
  try:
56
  response = requests.get(base_url, params=params) # No headers needed
57
  response.raise_for_status()
58
- weather_data = response.json()
 
 
 
 
59
  return weather_data
 
60
  except requests.exceptions.RequestException as e:
61
  print(f"Error fetching weather data: {e}")
62
  return None
@@ -64,7 +69,7 @@ def get_weather_forecast(city_name):
64
  print(f"Error decoding JSON response: {e}")
65
  return None
66
 
67
- def get_coordinates_no_api_key(city_name):
68
  """Gets coordinates using OpenStreetMap's Nominatim (no API key, but with limitations)."""
69
 
70
  # This approach is less reliable and might have rate limits.
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
  @tool
37
+ def get_weather_forecast(city_name: str) -> str:
38
  """A tool that fetches the current weather of a specified city.
39
  Args:
40
  city_name: A string representing a valid city (e.g., 'Bangalore').
 
55
  try:
56
  response = requests.get(base_url, params=params) # No headers needed
57
  response.raise_for_status()
58
+ weatherJSON = response.json())
59
+ cityName = weatherJSON.get('location').get('name')
60
+ cityTemp = weatherJSON.get('hourly').get('temperature_2m')
61
+ averageTemp = round(mean(cityTemp), 1)
62
+ hourlyunits = weatherJSON.get('hourly_units').get('temperature_2m')
63
  return weather_data
64
+ return f"The current Temperature in {cityName} is {averageTemp}{hourlyunits} and conditions are {cityCondition}"
65
  except requests.exceptions.RequestException as e:
66
  print(f"Error fetching weather data: {e}")
67
  return None
 
69
  print(f"Error decoding JSON response: {e}")
70
  return None
71
 
72
+ def get_coordinates_no_api_key(city_name: str) -> [float, float]:
73
  """Gets coordinates using OpenStreetMap's Nominatim (no API key, but with limitations)."""
74
 
75
  # This approach is less reliable and might have rate limits.