API to show details of user location

This commit is contained in:
Edward Betts 2021-06-25 11:12:50 +02:00
parent 81f8f7d426
commit 2fc233401e

View file

@ -209,16 +209,16 @@ def get_markers(all_items):
return items return items
def geoip_user_record():
def get_user_location():
gi = GeoIP.open(app.config["GEOIP_DATA"], GeoIP.GEOIP_STANDARD) gi = GeoIP.open(app.config["GEOIP_DATA"], GeoIP.GEOIP_STANDARD)
remote_ip = request.remote_addr remote_ip = request.remote_addr
gir = gi.record_by_addr(remote_ip) return gi.record_by_addr(remote_ip)
if not gir:
return
lat, lon = gir["latitude"], gir["longitude"] def get_user_location():
return (lat, lon) gir = geoip_user_record()
return (gir["latitude"], gir["longitude"]) if gir else None
@app.route("/") @app.route("/")
@ -414,6 +414,11 @@ def get_bbox_centroid(bbox):
return lat, lon return lat, lon
@app.route("/api/1/location")
def show_user_location():
return cors_jsonify(get_user_location())
@app.route("/api/1/count") @app.route("/api/1/count")
def api_wikidata_items_count(): def api_wikidata_items_count():
t0 = time() t0 = time()