Forgot a drop of code.
This commit is contained in:
parent
e2a43b8694
commit
9d9908ba68
1 changed files with 20 additions and 0 deletions
20
utils/user_info.py
Executable file
20
utils/user_info.py
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import requests
|
||||
|
||||
def location(character):
|
||||
"""
|
||||
Return a tuple of physical location information about
|
||||
the player playing `character`.
|
||||
"""
|
||||
session = character.sessions.get()[0]
|
||||
address = session.address
|
||||
if address == "127.0.0.1":
|
||||
return ("Localhost", None, None, address)
|
||||
|
||||
response = requests.get(f'https://ipapi.co/{address}/json/',
|
||||
timeout=1).json()
|
||||
city = response.get("city") or "Unknown City"
|
||||
region = response.get("region") or "Unknown Region"
|
||||
country = response.get("country_name") or "Unknown Country"
|
||||
return (city, region, country, address)
|
||||
Loading…
Reference in a new issue