lathashree01 commited on
Commit
cd6a167
·
verified ·
1 Parent(s): a28130e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -17,24 +17,21 @@ def get_weather(location:str,)-> dict: #it's import to specify the return type
17
  location: A string representing location (Eg. London)
18
  """
19
  api_key = os.getenv("openweatherapikey")
20
- base_url = "https://api.openweathermap.org/data/2.5/weather"
21
- params = {
22
- "q": location,
23
- "appid": api_key,
24
- "units": "metric" # Get temperature in Celsius
25
- }
26
- response = requests.get(base_url, params=params)
27
-
28
- if response.status_code == 200:
29
- data = response.json()
30
- return {
31
  "location": data["name"],
32
  "temperature": data["main"]["temp"],
33
  "weather": data["weather"][0]["description"]
34
  }
35
  else:
36
  return {"error": "Could not fetch weather data"}
37
-
38
  @tool
39
  def get_current_time_in_timezone(timezone: str) -> str:
40
  """A tool that fetches the current local time in a specified timezone.
 
17
  location: A string representing location (Eg. London)
18
  """
19
  api_key = os.getenv("openweatherapikey")
20
+ url = f'http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}'
21
+
22
+ response = requests.get(url)
23
+
24
+ if response.status_code == 200:
25
+ data = response.json()
26
+ temp = data['main']['temp']
27
+ desc = data['weather'][0]['description']
28
+ return {
 
 
29
  "location": data["name"],
30
  "temperature": data["main"]["temp"],
31
  "weather": data["weather"][0]["description"]
32
  }
33
  else:
34
  return {"error": "Could not fetch weather data"}
 
35
  @tool
36
  def get_current_time_in_timezone(timezone: str) -> str:
37
  """A tool that fetches the current local time in a specified timezone.