check for latitude and longitude before accessing them (#68)

This commit is contained in:
Jonathan Jenne
2019-12-22 17:53:28 +01:00
committed by Thomas Sileo
parent 3c4b9e7379
commit 657ab68355

View File

@@ -263,21 +263,24 @@ def has_place(note):
def get_place(note): def get_place(note):
if note.get("location") and note["location"].get("type") == "Place": if note.get("location") and note["location"].get("type") == "Place":
tag = note["location"] tag = note["location"]
lat = tag["latitude"] if tag.get("latitude") and tag.get("longitude"):
lng = tag["longitude"] lat = tag["latitude"]
out = "" lng = tag["longitude"]
if tag.get("name"): out = ""
out += f"{tag['name']} " if tag.get("name"):
out += f"{tag['name']} "
out += ( out += (
'<span class="h-geo">' '<span class="h-geo">'
f'<data class="p-latitude" value="{lat}"></data>' f'<data class="p-latitude" value="{lat}"></data>'
f'<data class="p-longitude" value="{lng}"></data>' f'<data class="p-longitude" value="{lng}"></data>'
f'<a href="https://www.openstreetmap.org/?mlat={lat}&mlon={lng}#map=16/{lat}/{lng}">{lat},{lng}</a>' f'<a href="https://www.openstreetmap.org/?mlat={lat}&mlon={lng}#map=16/{lat}/{lng}">{lat},{lng}</a>'
"</span>" "</span>"
) )
return out return out
return ""
return "" return ""