Lead location labels with neighbourhood; drop ±7-day window jargon (#18)

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').
This commit is contained in:
Emi Griffith 2026-07-11 00:02:19 -07:00 committed by GitHub
parent 95e735bf66
commit 28e6b5301f

View file

@ -488,17 +488,25 @@ def reverse_geocode(lat: float, lon: float) -> str | None:
try: try:
r = _request( r = _request(
"https://nominatim.openstreetmap.org/reverse", "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}, "addressdetails": 1},
15, 15,
phase="reverse_geocode", phase="reverse_geocode",
headers={"User-Agent": "Thermograph/0.1 (local weather grading app)"}, headers={"User-Agent": "Thermograph/0.1 (local weather grading app)"},
) )
a = r.json().get("address", {}) or {} 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") 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") 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 except Exception: # noqa: BLE001 - reverse geocoding is a nicety, never fatal
label = None label = None
_REVGEO_CACHE[key] = label _REVGEO_CACHE[key] = label