2011-11-20 10:23:31 +01:00
|
|
|
from util import hook
|
|
|
|
|
2012-03-12 19:13:32 +01:00
|
|
|
|
2011-11-21 06:18:22 +01:00
|
|
|
def find_location(ip, api):
|
2011-11-20 10:23:31 +01:00
|
|
|
import string
|
|
|
|
import urllib
|
2012-03-12 19:13:32 +01:00
|
|
|
response = urllib.urlopen("http://api.ipinfodb.com/v3/ip-city/?key=" \
|
|
|
|
+ api + "&ip=" + ip).read()
|
2011-11-20 10:23:31 +01:00
|
|
|
response = response.split(";")
|
|
|
|
give = {}
|
|
|
|
give["country"] = response[4].title()
|
|
|
|
give["country_short"] = response[3].upper()
|
|
|
|
give["state"] = response[5].title()
|
|
|
|
give["city"] = response[6].title()
|
|
|
|
give["timezone"] = response[10].title()
|
|
|
|
return give
|
|
|
|
|
2012-03-12 19:13:32 +01:00
|
|
|
|
2011-11-20 10:23:31 +01:00
|
|
|
def timezone(ip):
|
|
|
|
time = find_location(ip)["timezone"]
|
2012-02-29 09:29:53 +01:00
|
|
|
time = time.replace(":", ".")
|
|
|
|
time = time.replace(".00", "")
|
2011-11-20 10:23:31 +01:00
|
|
|
return int(time)
|
|
|
|
|
2012-02-29 09:29:53 +01:00
|
|
|
|
2011-11-20 10:23:31 +01:00
|
|
|
@hook.command
|
2011-11-21 08:14:21 +01:00
|
|
|
@hook.command("location")
|
2012-02-29 09:29:53 +01:00
|
|
|
def geoip(inp, say=None, bot=None):
|
2012-02-28 03:03:43 +01:00
|
|
|
".geoip <ip> - Performs a location check on <ip>."
|
2012-02-15 19:18:56 +01:00
|
|
|
api_key = bot.config.get("api_keys", {}).get("geoip", None)
|
|
|
|
if api_key is None:
|
|
|
|
return "error: no api key set"
|
|
|
|
give = find_location(inp, api_key)
|
2012-02-29 09:29:53 +01:00
|
|
|
if give["country"] not in ["", " ", "-", " - "]:
|
2011-11-20 10:23:31 +01:00
|
|
|
if give["state"] == give["city"]:
|
2012-02-29 09:29:53 +01:00
|
|
|
localstring = give["city"]
|
2011-11-20 10:23:31 +01:00
|
|
|
else:
|
|
|
|
localstring = give["city"] + ", " + give["state"]
|
2012-04-02 18:17:55 +02:00
|
|
|
say("That IP comes from " + give["country"] +
|
|
|
|
" (" + give["country_short"] + ")")
|
|
|
|
say("I think it's in " + localstring +
|
|
|
|
" with a timezone of " + give["timezone"] + "GMT")
|
2011-11-20 10:23:31 +01:00
|
|
|
else:
|
2012-04-02 18:17:55 +02:00
|
|
|
say("Either that wasn't an IP or I cannot locate it in my database.")
|
2011-11-20 10:23:31 +01:00
|
|
|
return
|