from banapedia.wapi.WikipediaQuery import BlockQuery from datetime import datetime import pygeoip __author__ = 'pacien' GEOIP_FILE = "/usr/share/GeoIP/GeoIP.dat" geoip = pygeoip.GeoIP(GEOIP_FILE) ISO_TIMESTAMP = "%Y-%m-%dT%H:%M:%SZ" class Ban: def __init__(self, ip, start, end): self.ip = ip self.start = start self.end = end self.country_code = None def get_duration(self): return (self.end - self.start).days def get_country_code(self): if self.country_code is not None: return self.country_code country_code = "" try: country_code = geoip.country_code_by_addr(self.ip).lower() except pygeoip.GeoIPError: print("[ERROR]", "Could not determine country for ip", self.ip) self.country_code = country_code return country_code