summaryrefslogtreecommitdiff
path: root/foreign/utility/location_data.py
diff options
context:
space:
mode:
Diffstat (limited to 'foreign/utility/location_data.py')
-rw-r--r--foreign/utility/location_data.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/foreign/utility/location_data.py b/foreign/utility/location_data.py
new file mode 100644
index 0000000..2414593
--- /dev/null
+++ b/foreign/utility/location_data.py
@@ -0,0 +1,16 @@
+import requests
+
+
+def location_data():
+ try:
+ location = requests.get('http://ipinfo.io').json()
+ except:
+ return {'address': '???', 'location': '???'}
+ else:
+ try:
+ return {'address': location['ip'], 'location': f'{location["city"]} ({location["country"]})'}
+ except:
+ try:
+ return {'address': location['ip'], 'location': '???'}
+ except:
+ return {'address': '???', 'location': '???'} \ No newline at end of file