diff options
author | Pacien TRAN-GIRARD | 2014-10-24 19:59:05 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-10-24 19:59:05 +0200 |
commit | bdf9099df8c2a4636b0ad0e710b73330877eef37 (patch) | |
tree | 63fd704f15f3030f1455aad0ef92403c5d093c70 /banapedia/Ban.py | |
parent | 16529a0d212e1387eacd590c0e5e1b1a13dc2641 (diff) | |
download | wikistats-bdf9099df8c2a4636b0ad0e710b73330877eef37.tar.gz |
Very cleaner, much class, such readable, wow
Diffstat (limited to 'banapedia/Ban.py')
-rw-r--r-- | banapedia/Ban.py | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/banapedia/Ban.py b/banapedia/Ban.py deleted file mode 100644 index 4714274..0000000 --- a/banapedia/Ban.py +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | from banapedia.wapi.WikipediaQuery import BlockQuery | ||
2 | from datetime import datetime | ||
3 | import pygeoip | ||
4 | |||
5 | __author__ = 'pacien' | ||
6 | |||
7 | |||
8 | GEOIP_FILE = "/usr/share/GeoIP/GeoIP.dat" | ||
9 | geoip = pygeoip.GeoIP(GEOIP_FILE) | ||
10 | |||
11 | ISO_TIMESTAMP = "%Y-%m-%dT%H:%M:%SZ" | ||
12 | |||
13 | |||
14 | class Ban: | ||
15 | def __init__(self, ip, start, end): | ||
16 | self.ip = ip | ||
17 | self.start = start | ||
18 | self.end = end | ||
19 | self.country_code = None | ||
20 | |||
21 | def get_duration(self): | ||
22 | return (self.end - self.start).days | ||
23 | |||
24 | def get_country_code(self): | ||
25 | if self.country_code is not None: | ||
26 | return self.country_code | ||
27 | |||
28 | country_code = "" | ||
29 | |||
30 | try: | ||
31 | country_code = geoip.country_code_by_addr(self.ip).lower() | ||
32 | except pygeoip.GeoIPError: | ||
33 | print("[ERROR]", "Could not determine country for ip", self.ip) | ||
34 | |||
35 | self.country_code = country_code | ||
36 | return country_code | ||