Skip to content

Instantly share code, notes, and snippets.

@ask-compu
Created January 9, 2016 14:53
Show Gist options
  • Save ask-compu/25e3fee2906fe05121fe to your computer and use it in GitHub Desktop.
Save ask-compu/25e3fee2906fe05121fe to your computer and use it in GitHub Desktop.
def geoip_search(query):
query = query.replace('!', '')
query = web.quote(query)
uri = 'https://freegeoip.net/json/' + query
#try:
rec_bytes = web.get(uri)
#except:
# return
jsonstring = json.loads(rec_bytes)
ip = jsonstring['ip']
country = jsonstring['country_name']
countrycode = jsonstring['country_code']
state = jsonstring['region_name']
statecode = jsonstring['region_code']
city = jsonstring['city']
zipcode = jsonstring['zip_code']
timezone = jsonstring['time_zone']
#if not country or countrycode == "RU":
# return
#else:
return str(jsonstring)
#return(ip + ' is in ' + city + ', ' + state + ', ' + country + ', ' + zipcode + ' in the "' + timezone + '" timezone')
def geoip(phenny, input):
"""Performs IP address geolocation."""
query = input.group(2)
if not query: return phenny.reply('.geo what?')
uri = geoip_search(query)
phenny.say("test: " + uri)
if uri:
phenny.say("Here's what I got, " + input.nick + ": " + uri)
if not hasattr(phenny.bot, 'last_seen_uri'):
phenny.bot.last_seen_uri = {}
phenny.bot.last_seen_uri[input.sender] = uri
else: phenny.say("Sorry " + input.nick + ", I couldn't find anything for '%s'." % query)
wikipedia.commands = ['geo', 'geoip']
wikipedia.example = '.geo google.com'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment