Created
January 20, 2017 10:00
-
-
Save mortymacs/07cea191827113a82bea801a76bd3315 to your computer and use it in GitHub Desktop.
Get current location (country/city name)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2 | |
| import urllib | |
| import json | |
| try: | |
| body = urllib.urlopen("http://ip-api.com/json").read() | |
| body = json.loads(body) | |
| print body.get('country'),"/",body.get("city") | |
| except: | |
| print("Connection failed!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment