Bug fixes
This commit is contained in:
parent
529611b42c
commit
a5f7ba917d
19
lookup.py
19
lookup.py
|
@ -51,10 +51,10 @@ def lat_lon_to_wikidata(lat, lon):
|
||||||
result = do_lookup(elements, lat, lon)
|
result = do_lookup(elements, lat, lon)
|
||||||
|
|
||||||
# special case because the City of London is admin_level=6 in OSM
|
# special case because the City of London is admin_level=6 in OSM
|
||||||
if result["wikidata"] == city_of_london_qid:
|
if result.get("wikidata") == city_of_london_qid:
|
||||||
return {"elements": elements, "result": result}
|
return {"elements": elements, "result": result}
|
||||||
|
|
||||||
admin_level = result["admin_level"]
|
admin_level = result.get("admin_level")
|
||||||
|
|
||||||
if not admin_level or admin_level >= 7:
|
if not admin_level or admin_level >= 7:
|
||||||
return {"elements": elements, "result": result}
|
return {"elements": elements, "result": result}
|
||||||
|
@ -69,8 +69,6 @@ def lat_lon_to_wikidata(lat, lon):
|
||||||
|
|
||||||
|
|
||||||
def osm_lookup(elements, lat, lon):
|
def osm_lookup(elements, lat, lon):
|
||||||
elements = sorted(elements, key=lambda e: e.area)
|
|
||||||
|
|
||||||
for e in elements:
|
for e in elements:
|
||||||
tags = e.tags
|
tags = e.tags
|
||||||
admin_level_tag = tags.get("admin_level")
|
admin_level_tag = tags.get("admin_level")
|
||||||
|
@ -177,7 +175,18 @@ def detail_page():
|
||||||
lat, lon = [float(request.args.get(param)) for param in ("lat", "lon")]
|
lat, lon = [float(request.args.get(param)) for param in ("lat", "lon")]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
reply = lat_lon_to_wikidata(lat, lon)
|
try:
|
||||||
|
reply = lat_lon_to_wikidata(lat, lon)
|
||||||
|
except wikidata.QueryError as e:
|
||||||
|
query, r = e.args
|
||||||
|
return render_template(
|
||||||
|
"query_error.html",
|
||||||
|
lat=lat,
|
||||||
|
lon=lon,
|
||||||
|
query=query,
|
||||||
|
r=r
|
||||||
|
)
|
||||||
|
|
||||||
return render_template("detail.html", lat=lat, lon=lon, **reply)
|
return render_template("detail.html", lat=lat, lon=lon, **reply)
|
||||||
|
|
||||||
|
|
||||||
|
|
28
templates/query_error.html
Normal file
28
templates/query_error.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Geocode to commons</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Geocode coordinates to Commons Category</h1>
|
||||||
|
|
||||||
|
<p><a href="{{ url_for('index', lat=lat, lon=lon) }}">visit endpoint</a>
|
||||||
|
|
||||||
|
| <a href="https://www.openstreetmap.org/#map=17/{{lat }}/{{ lon }}">view in OSM</a>
|
||||||
|
|
||||||
|
| <a href="{{ url_for('detail_page', lat=lat, lon=lon) }}">#</a>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>query</h2>
|
||||||
|
|
||||||
|
<pre>{{ query }}</pre>
|
||||||
|
|
||||||
|
<h2>reply</h2>
|
||||||
|
|
||||||
|
<pre>{{ r.text }}</pre>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue