mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Defensive coding
This commit is contained in:
+4
-3
@@ -109,12 +109,13 @@ def populate_sig_ref_info(sig_ref):
|
||||
# the zeroest corner of the box, then "lat2" and "lng2" provide the other corner. We detect this
|
||||
# and provide a single lat/lon for the centre. Otherwise if we don't have these extra parameters,
|
||||
# just use the single point we have.
|
||||
if "latitude" in data and "longitude" in data and "lat2" in data and "lng2" in data:
|
||||
if data.get("latitude") is not None and data.get("longitude") is not None and data.get(
|
||||
"lat2") is not None and data.get("lng2") is not None:
|
||||
sig_ref.latitude = (float(data["latitude"]) + float(data["lat2"])) / 2.0
|
||||
sig_ref.longitude = (float(data["longitude"]) + float(data["lng2"])) / 2.0
|
||||
else:
|
||||
sig_ref.latitude = float(data["latitude"]) if "latitude" in data else None
|
||||
sig_ref.longitude = float(data["longitude"]) if "longitude" in data else None
|
||||
sig_ref.latitude = float(data["latitude"]) if data.get("latitude") is not None else None
|
||||
sig_ref.longitude = float(data["longitude"]) if data.get("longitude") is not None else None
|
||||
elif not response.from_cache:
|
||||
logging.warning("Malformed response looking up %s ref %s via GMA", sig, ref_id)
|
||||
elif not response.from_cache:
|
||||
|
||||
Reference in New Issue
Block a user