Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Created January 20, 2017 10:00
Show Gist options
  • Select an option

  • Save mortymacs/07cea191827113a82bea801a76bd3315 to your computer and use it in GitHub Desktop.

Select an option

Save mortymacs/07cea191827113a82bea801a76bd3315 to your computer and use it in GitHub Desktop.
Get current location (country/city name)
#!/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