From 2fc233401e91c7cbaeb4522b622d88e30098fae8 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 25 Jun 2021 11:12:50 +0200 Subject: [PATCH] API to show details of user location --- web_view.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/web_view.py b/web_view.py index 7543a46..03b11b9 100755 --- a/web_view.py +++ b/web_view.py @@ -209,16 +209,16 @@ def get_markers(all_items): return items - -def get_user_location(): +def geoip_user_record(): gi = GeoIP.open(app.config["GEOIP_DATA"], GeoIP.GEOIP_STANDARD) remote_ip = request.remote_addr - gir = gi.record_by_addr(remote_ip) - if not gir: - return - lat, lon = gir["latitude"], gir["longitude"] - return (lat, lon) + return gi.record_by_addr(remote_ip) + + +def get_user_location(): + gir = geoip_user_record() + return (gir["latitude"], gir["longitude"]) if gir else None @app.route("/") @@ -414,6 +414,11 @@ def get_bbox_centroid(bbox): return lat, lon +@app.route("/api/1/location") +def show_user_location(): + return cors_jsonify(get_user_location()) + + @app.route("/api/1/count") def api_wikidata_items_count(): t0 = time()