clwuyang commited on
Commit
bff6769
·
verified ·
1 Parent(s): 5727f74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -16,14 +16,25 @@ def get_city_weather(city:str)-> str: #it's import to specify the return type
16
  Args:
17
  city: A string representing a valid city (e.g., 'Chicago')
18
  """
19
- weather_API = os.getenv('weather_API')
20
- api_url = f"ttp://api.weatherapi.com/v1/current.json?key={weather_API}v&q={city}&aqi=no"
21
- response = requests.get(api_url)
22
- if response.status_code == 200:
 
 
 
 
23
  data = response.json()
24
- return data.get("temp_c", "No weather information available")
25
- else:
26
- return "Error: Unable to fetch weather data."
 
 
 
 
 
 
 
27
 
28
  @tool
29
  def get_current_time_in_timezone(timezone: str) -> str:
 
16
  Args:
17
  city: A string representing a valid city (e.g., 'Chicago')
18
  """
19
+ weather_API = os.getenv("weather_API") # Ensure this is set
20
+ if not weather_API:
21
+ return "Error: Weather API key is missing."
22
+
23
+ api_url = f"https://api.weatherapi.com/v1/current.json?key={weather_API}&q={city}&aqi=no"
24
+ try:
25
+ response = requests.get(api_url)
26
+ response.raise_for_status() # Raise an error for non-200 responses
27
  data = response.json()
28
+
29
+ if "current" in data:
30
+ temp = data["current"]["temp_c"]
31
+ condition = data["current"]["condition"]["text"]
32
+ return f"The temperature in {city} is {temp}°C with {condition}."
33
+ else:
34
+ return "Error: Weather data not available."
35
+
36
+ except requests.exceptions.RequestException as e:
37
+ return f"Error: Unable to fetch weather data. {e}"
38
 
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str: