From f882b694b9e317d2151fc5b02928aabe5417289b Mon Sep 17 00:00:00 2001 From: Shane Date: Sat, 22 Aug 2026 16:23:09 -0400 Subject: [PATCH] fix: report weather in Fahrenheit by default --- agent/weather_mcp.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/agent/weather_mcp.py b/agent/weather_mcp.py index 5d3d248..18f0556 100644 --- a/agent/weather_mcp.py +++ b/agent/weather_mcp.py @@ -24,14 +24,19 @@ WTTR_BASE = os.environ.get("WTTR_BASE", "https://wttr.in").rstrip("/") mcp = FastMCP("weather") +def _c_to_f(c: str | int) -> int: + """Convert Celsius to Fahrenheit (rounds to whole degrees).""" + return round(int(c) * 9 / 5 + 32) + + def _summarize(data: dict, location: str) -> str: """Build a short spoken-style weather summary from wttr.in j1 JSON.""" current = data.get("current_condition", [{}])[0] or {} area = data.get("nearest_area", [{}])[0] or {} city = (area.get("areaName", [{}])[0].get("value") or location).strip() - temp_c = current.get("temp_C") - feels_c = current.get("FeelsLikeC") + temp_f = _c_to_f(current["temp_C"]) if current.get("temp_C") is not None else None + feels_f = _c_to_f(current["FeelsLikeC"]) if current.get("FeelsLikeC") is not None else None desc = (current.get("weatherDesc", [{}])[0].get("value") or "").strip().lower() astronomy = data.get("astronomy", [{}])[0] or {} @@ -39,19 +44,19 @@ def _summarize(data: dict, location: str) -> str: sunset = astronomy.get("sunset", "") today = (data.get("weather") or [None])[0] or {} - high_c = today.get("maxtempC") - min_c = today.get("mintempC") + high_f = _c_to_f(today["maxtempC"]) if today.get("maxtempC") is not None else None + low_f = _c_to_f(today["mintempC"]) if today.get("mintempC") is not None else None parts: list[str] = [] - if temp_c is not None: - lead = f"It's {temp_c} degrees and {desc or 'clear'} in {city}" - if feels_c is not None and feels_c != temp_c: - lead += f", feels like {feels_c}" + if temp_f is not None: + lead = f"It's {temp_f} degrees and {desc or 'clear'} in {city}" + if feels_f is not None and feels_f != temp_f: + lead += f", feels like {feels_f}" parts.append(lead + ".") - if high_c is not None and min_c is not None: - parts.append(f"Today's high is {high_c} and the low is {min_c}.") + if high_f is not None and low_f is not None: + parts.append(f"Today's high is {high_f} and the low is {low_f}.") if sunrise and sunset: parts.append(f"Sunrise was at {sunrise} and sunset is at {sunset}.") @@ -65,7 +70,7 @@ async def get_weather(location: str) -> str: Use this when the user asks about current conditions, temperature, or the forecast for a place. Returns a short conversational summary - suitable for reading aloud (1-2 sentences). + in Fahrenheit suitable for reading aloud (1-2 sentences). """ try: async with httpx.AsyncClient(timeout=30) as client: