aboutsummaryrefslogtreecommitdiff
path: root/actions/location.py
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-04-09 16:39:03 +0200
committerMinteck <contact@minteck.org>2022-04-09 16:40:02 +0200
commit0f8967b9113d698cdeb2d05ca85d2d9a80461c24 (patch)
tree00664ddd9c55a2c33631fd1bd33e556cea9c67e5 /actions/location.py
parentdac03ac82bc0f8044a4b339c27b5390e4dcecf2f (diff)
downloadvoicer-trunk.tar.gz
voicer-trunk.tar.bz2
voicer-trunk.zip
CommitHEADtrunk
Diffstat (limited to 'actions/location.py')
-rw-r--r--actions/location.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/actions/location.py b/actions/location.py
new file mode 100644
index 0000000..4eee869
--- /dev/null
+++ b/actions/location.py
@@ -0,0 +1,22 @@
+import urllib
+from urllib.request import urlopen, Request
+import ssl
+import json
+
+
+# noinspection PyUnresolvedReferences
+def _action_location(_input):
+ try:
+ ctx = ssl.create_default_context()
+ ctx.check_hostname = False
+ ctx.verify_mode = ssl.CERT_NONE
+
+ ip = urlopen(Request("https://ip.me", headers={"User-Agent": "curl/0.0.0"}), context=ctx).read().decode("utf-8")\
+ .strip()
+ location = json.loads(urlopen(Request("https://ipinfo.io/" + ip + "/json", headers={"User-Agent": "curl/0.0.0"}),
+ context=ctx).read().decode("utf-8").strip())
+ say(f"Vous êtes à {location['city']}, {location['region']}")
+ except urllib.error.URLError:
+ say("Désolé, je ne parviens pas à accéder à Internet en ce moment. Vérifiez que votre appareil dispose d'une"
+ "connexion Internet stable et réessayez.")
+ return