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