From 164b18b7420942ef5aae2dc20755116e58ba8bad Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Wed, 18 Jul 2012 02:54:04 -0400 Subject: [PATCH] Fixing !geolocate when IP is reserved or unknown. --- earwigbot/commands/geolocate.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/earwigbot/commands/geolocate.py b/earwigbot/commands/geolocate.py index 90c02ed..6bb8327 100644 --- a/earwigbot/commands/geolocate.py +++ b/earwigbot/commands/geolocate.py @@ -56,16 +56,18 @@ class Geolocate(Command): query = urllib2.urlopen(url.format(self.key, address)).read() res = json.loads(query) - try: - country = res["countryName"].title() - region = res["regionName"].title() - city = res["cityName"].title() - latitude = res["latitude"] - longitude = res["longitude"] - utcoffset = res["timeZone"] - except KeyError: + country = res["countryName"].title() + region = res["regionName"].title() + city = res["cityName"].title() + latitude = res["latitude"] + longitude = res["longitude"] + utcoffset = res["timeZone"] + if not country and not region and not city: self.reply(data, "IP \x0302{0}\x0F not found.".format(address)) return + if country == "-" and region == "-" and city == "-": + self.reply(data, "IP \x0302{0}\x0F is reserved.".format(address)) + return msg = "{0}, {1}, {2} ({3}, {4}), UTC {5}" geo = msg.format(country, region, city, latitude, longitude, utcoffset)