From 747e9dec48d232ac3fb22d16e4e86dbd9825b656 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 17 Jan 2024 11:48:33 +0000 Subject: [PATCH] Avoid crash for lat/lon in UK EEZ Handle Wiidata items without a Commons sitelink --- geocode/wikidata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geocode/wikidata.py b/geocode/wikidata.py index ba209b9..16edc7f 100644 --- a/geocode/wikidata.py +++ b/geocode/wikidata.py @@ -196,7 +196,6 @@ def build_dict(hit: Hit | None, lat: float, lon: float) -> WikidataDict: coords = {"lat": lat, "lon": lon} if hit is None: return {"commons_cat": None, "missing": True, "coords": coords} - assert isinstance(hit["commons_cat"], str) commons_cat = hit["commons_cat"] ret: WikidataDict = { "coords": coords, @@ -208,6 +207,7 @@ def build_dict(hit: Hit | None, lat: float, lon: float) -> WikidataDict: if not commons_cat: return ret + assert isinstance(commons_cat, str) url = commons_cat_start + urllib.parse.quote(commons_cat.replace(" ", "_")) ret["commons_cat"] = {"title": commons_cat, "url": url}