feat: Add optional location name to weather report
All checks were successful
Docker CI/CD / Docker Build and Push to Docker Hub (push) Successful in 9m33s
All checks were successful
Docker CI/CD / Docker Build and Push to Docker Hub (push) Successful in 9m33s
This update allows users to provide a location name for their weather reports, which can be useful when requesting weather information for specific locations.
This commit is contained in:
parent
9a4c250eb4
commit
e46be65707
1 changed files with 7 additions and 1 deletions
|
@ -17,6 +17,10 @@ class Weather(BaseTool):
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The longitude of the location.",
|
"description": "The longitude of the location.",
|
||||||
},
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A location name to include in the report. This is optional, latitude and longitude are always required."
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"required": ["latitude", "longitude"],
|
"required": ["latitude", "longitude"],
|
||||||
}
|
}
|
||||||
|
@ -26,6 +30,8 @@ class Weather(BaseTool):
|
||||||
if not (latitude := self.kwargs.get("latitude")) or not (longitude := self.kwargs.get("longitude")):
|
if not (latitude := self.kwargs.get("latitude")) or not (longitude := self.kwargs.get("longitude")):
|
||||||
raise Exception('No location provided.')
|
raise Exception('No location provided.')
|
||||||
|
|
||||||
|
name = self.kwargs.get("name")
|
||||||
|
|
||||||
weather_api_key = self.bot.config.get("OpenWeatherMap", "APIKey")
|
weather_api_key = self.bot.config.get("OpenWeatherMap", "APIKey")
|
||||||
|
|
||||||
if not weather_api_key:
|
if not weather_api_key:
|
||||||
|
@ -37,7 +43,7 @@ class Weather(BaseTool):
|
||||||
async with session.get(url) as response:
|
async with session.get(url) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
return f"""**Weather report**
|
return f"""**Weather report{f" for {name}" if name else ""}**
|
||||||
Current: {data['current']['temp']}°C, {data['current']['weather'][0]['description']}
|
Current: {data['current']['temp']}°C, {data['current']['weather'][0]['description']}
|
||||||
Feels like: {data['current']['feels_like']}°C
|
Feels like: {data['current']['feels_like']}°C
|
||||||
Humidity: {data['current']['humidity']}%
|
Humidity: {data['current']['humidity']}%
|
||||||
|
|
Loading…
Reference in a new issue