Created
August 21, 2011 20:06
-
-
Save marcelcaraciolo/1161085 to your computer and use it in GitHub Desktop.
ip_location API Example
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
| 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