From 28e6b5301ff83469f16d654af4f3744b9c0d4b07 Mon Sep 17 00:00:00 2001 From: Emi Griffith Date: Sat, 11 Jul 2026 00:02:19 -0700 Subject: [PATCH] =?UTF-8?q?Lead=20location=20labels=20with=20neighbourhood?= =?UTF-8?q?;=20drop=20=C2=B17-day=20window=20jargon=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reverse-geocode at zoom 14 and prefer neighbourhood/suburb ahead of the city so labels read 'Gowanus, New York' when OSM has that detail, falling back to the city (and county) when it doesn't. Replace the recurring '±7-day window' phrasing in the UI with plain language ('a typical day', 'days around this date', 'typical climate'). --- climate.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/climate.py b/climate.py index c1266ab..5db0b81 100644 --- a/climate.py +++ b/climate.py @@ -488,17 +488,25 @@ def reverse_geocode(lat: float, lon: float) -> str | None: try: r = _request( "https://nominatim.openstreetmap.org/reverse", - {"lat": lat, "lon": lon, "format": "jsonv2", "zoom": 10, + # zoom 14 resolves to the suburb/neighbourhood level so we can lead + # with it when OSM has one (zoom 10 only ever returns the city). + {"lat": lat, "lon": lon, "format": "jsonv2", "zoom": 14, "addressdetails": 1}, 15, phase="reverse_geocode", headers={"User-Agent": "Thermograph/0.1 (local weather grading app)"}, ) a = r.json().get("address", {}) or {} + # Lead with the neighbourhood when available, then the city, then region. + neighborhood = (a.get("neighbourhood") or a.get("suburb") + or a.get("quarter") or a.get("city_district") + or a.get("borough")) city = (a.get("city") or a.get("town") or a.get("village") - or a.get("hamlet") or a.get("suburb") or a.get("county")) + or a.get("hamlet") or a.get("county")) region = a.get("state") or a.get("province") or a.get("region") - label = ", ".join(p for p in (city, region) if p) or None + # dict.fromkeys drops duplicates (e.g. neighbourhood == city) in order. + parts = dict.fromkeys(p for p in (neighborhood, city, region) if p) + label = ", ".join(parts) or None except Exception: # noqa: BLE001 - reverse geocoding is a nicety, never fatal label = None _REVGEO_CACHE[key] = label