INNER CODE UNIT · Python
getForecast
existence-master/Sentient · src/server/mcp_hub/accuweather/main.py:64
async def getForecast(ctx: Context, location: str, days: int = 1) -> Dict[str, Any]:
"""
Retrieves the daily weather forecast for a specified location for up to 5 days. The forecast includes minimum and maximum temperatures and day/night weather conditions.
"""
logger.info(f"Executing tool: getForecast with location='{location}', days={days}")
try:
if not 1 <= days <= 5:
raise ToolError("Forecast can only be retrieved for 1 to 5 days.")
api_key = auth.get_accuweather_api_key()
location_details = await utils.get_location_details(location, api_key)
forecast_data = await utils.fetch_daily_forecast(location_details["key"], api_key)
daily_forecasts = []
for day_forecast in forecast_data.get("DailyForecasts", [])[:days]:
daily_forecasts.append({
"date": day_forecast.get("Date"),
"temperature_min": day_forecast.get("Temperature", {}).get("Minimum"),