Log FQDN
This commit is contained in:
parent
4720814e1f
commit
231cab309d
|
@ -93,4 +93,5 @@ class LookupLog(Base):
|
||||||
lat = Column(Float)
|
lat = Column(Float)
|
||||||
lon = Column(Float)
|
lon = Column(Float)
|
||||||
remote_addr = Column(String)
|
remote_addr = Column(String)
|
||||||
|
fqdn = Column(String)
|
||||||
result = Column(postgresql.JSONB)
|
result = Column(postgresql.JSONB)
|
||||||
|
|
18
lookup.py
18
lookup.py
|
@ -2,6 +2,7 @@
|
||||||
"""Reverse geocode: convert lat/lon to Wikidata item & Wikimedia Commons category."""
|
"""Reverse geocode: convert lat/lon to Wikidata item & Wikimedia Commons category."""
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
import socket
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
import sqlalchemy.exc
|
import sqlalchemy.exc
|
||||||
|
@ -18,6 +19,7 @@ app.config.from_object("config.default")
|
||||||
database.init_app(app)
|
database.init_app(app)
|
||||||
|
|
||||||
Tags = typing.Mapping[str, str]
|
Tags = typing.Mapping[str, str]
|
||||||
|
logging_enabled = True
|
||||||
|
|
||||||
|
|
||||||
def get_random_lat_lon() -> tuple[float, float]:
|
def get_random_lat_lon() -> tuple[float, float]:
|
||||||
|
@ -193,11 +195,17 @@ def index() -> str | Response:
|
||||||
result = lat_lon_to_wikidata(lat, lon)["result"]
|
result = lat_lon_to_wikidata(lat, lon)["result"]
|
||||||
result.pop("element", None)
|
result.pop("element", None)
|
||||||
result.pop("geojson", None)
|
result.pop("geojson", None)
|
||||||
log = model.LookupLog(
|
if logging_enabled:
|
||||||
lat=lat, lon=lon, remote_addr=request.remote_addr, result=result
|
remote_addr = request.headers.get("X-Forwarded-For", request.remote_addr)
|
||||||
)
|
log = model.LookupLog(
|
||||||
database.session.add(log)
|
lat=lat,
|
||||||
database.session.commit()
|
lon=lon,
|
||||||
|
remote_addr=remote_addr,
|
||||||
|
fqdn=socket.getfqdn(remote_addr),
|
||||||
|
result=result,
|
||||||
|
)
|
||||||
|
database.session.add(log)
|
||||||
|
database.session.commit()
|
||||||
return jsonify(result)
|
return jsonify(result)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue