blob: 471427473d0a256efb05e813abd1467226255b22 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
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
|