Pārlūkot izejas kodu

Fixing !geolocate when IP is reserved or unknown.

tags/v0.1^2
Ben Kurtovic pirms 12 gadiem
vecāks
revīzija
164b18b742
1 mainītis faili ar 10 papildinājumiem un 8 dzēšanām
  1. +10
    -8
      earwigbot/commands/geolocate.py

+ 10
- 8
earwigbot/commands/geolocate.py Parādīt failu

@@ -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)


Notiek ielāde…
Atcelt
Saglabāt