use "city, state, country" for formatted location name when available

This commit is contained in:
jesopo 2019-06-18 16:50:46 +01:00
parent 14303f354c
commit 398bd7e117

View file

@ -19,6 +19,19 @@ class Module(ModuleManager.BaseModule):
timezone = result["annotations"]["timezone"]["name"] timezone = result["annotations"]["timezone"]["name"]
lat = result["geometry"]["lat"] lat = result["geometry"]["lat"]
lon = result["geometry"]["lng"] lon = result["geometry"]["lng"]
name = result["formatted"]
name_parts = []
components = result["components"]
if "city" in components:
name_parts.append(components["city"])
if "state" in components:
name_parts.append(components["state"])
if "country" in components:
name_parts.append(components["country"])
if not name_parts:
name_parts.append(result["formatted"])
name = ", ".join(name_parts)
return {"timezone": timezone, "lat": lat, "lon": lon, "name": name} return {"timezone": timezone, "lat": lat, "lon": lon, "name": name}