Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created August 21, 2011 20:06
Show Gist options
  • Select an option

  • Save marcelcaraciolo/1161085 to your computer and use it in GitHub Desktop.

Select an option

Save marcelcaraciolo/1161085 to your computer and use it in GitHub Desktop.
ip_location API Example
import json
import urllib
API_KEY = "7084a6cb5d680c54df55fb3401ba042bfe9e5d55f61b65f0d8f027e0a0f486b2"
IP = '187.41.231.167'
url = "http://api.ipinfodb.com/v3/ip-city/?key=%s&ip=%s&format=json" % (API_KEY, IP)
response = urllib.urlopen(url).read()
dados = json.loads(response)
print dados
'''
{u'cityName': u'RIO DE JANEIRO',
u'countryCode': u'BR',
u'countryName': u'BRAZIL',
u'ipAddress': u'187.41.231.167',
u'latitude': u'-22.9',
u'longitude': u'-43.233',
u'regionName': u'RIO DE JANEIRO',
u'statusCode': u'OK',
u'statusMessage': u'',
u'timeZone': u'-03:00',
u'zipCode': u'-'}
'''
print dados['regionName']
#u'RIO DE JANEIRO'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment