new: [mygeolookup] Query on root of the server will give the geo location of the remote IP address doing the query.

This commit is contained in:
Alexandre Dulaunoy 2022-01-24 08:51:24 +01:00
parent dd484f83a3
commit eb37aa0cc9
Signed by: adulau
GPG key ID: 09E2CD4944E6CBCD

View file

@ -62,6 +62,19 @@ class GeoLookup:
georesult = q.get(value) georesult = q.get(value)
ret.append(georesult) ret.append(georesult)
georesult['meta'] = meta georesult['meta'] = meta
georesult['ip'] = value
resp.media = ret
return
class MyGeoLookup:
def on_get(self, req, resp):
ret = []
ips = req.access_route
georesult = q.get(ips[0])
ret.append(georesult)
georesult['meta'] = meta
georesult['ip'] = ips[0]
resp.media = ret resp.media = ret
return return
@ -69,6 +82,7 @@ class GeoLookup:
app = falcon.App() app = falcon.App()
app.add_route('/geolookup/{value}', GeoLookup()) app.add_route('/geolookup/{value}', GeoLookup())
app.add_route('/', MyGeoLookup())
if __name__ == '__main__': if __name__ == '__main__':
with make_server('', 8000, app) as httpd: with make_server('', 8000, app) as httpd: