From bdf9099df8c2a4636b0ad0e710b73330877eef37 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 24 Oct 2014 19:59:05 +0200 Subject: Very cleaner, much class, such readable, wow --- banapedia/Ban.py | 36 ---------------------------------- banapedia/__init__.py | 1 - banapedia/api/Query.py | 23 ---------------------- banapedia/api/__init__.py | 0 banapedia/wapi/WikipediaQuery.py | 42 ---------------------------------------- banapedia/wapi/__init__.py | 0 6 files changed, 102 deletions(-) delete mode 100644 banapedia/Ban.py delete mode 100644 banapedia/__init__.py delete mode 100644 banapedia/api/Query.py delete mode 100644 banapedia/api/__init__.py delete mode 100644 banapedia/wapi/WikipediaQuery.py delete mode 100644 banapedia/wapi/__init__.py (limited to 'banapedia') 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 @@ -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 diff --git a/banapedia/__init__.py b/banapedia/__init__.py deleted file mode 100644 index 8b13789..0000000 --- a/banapedia/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/banapedia/api/Query.py b/banapedia/api/Query.py deleted file mode 100644 index 7453df9..0000000 --- a/banapedia/api/Query.py +++ /dev/null @@ -1,23 +0,0 @@ -import urllib.parse -import urllib.request -import json - -__author__ = 'pacien' - - -class Query: - def __init__(self, base_url="", params={}, encoding="utf8"): - self.base_url = base_url - self.params = params - self.encoding = encoding - - def fetch_raw_result(self): - post_query = urllib.parse.urlencode(self.params) - post_query = post_query.encode(self.encoding) - document = urllib.request.urlopen(self.base_url, post_query) - return document.read().decode(self.encoding) - - -class JSONQuery(Query): - def fetch_result(self): - return json.loads(self.fetch_raw_result()) diff --git a/banapedia/api/__init__.py b/banapedia/api/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/banapedia/wapi/WikipediaQuery.py b/banapedia/wapi/WikipediaQuery.py deleted file mode 100644 index d3d2f94..0000000 --- a/banapedia/wapi/WikipediaQuery.py +++ /dev/null @@ -1,42 +0,0 @@ -from ..api.Query import JSONQuery - -__author__ = 'pacien' - -WIKIPEDIA_QUERY_BASE_URL = "https://en.wikipedia.org/w/api.php" -LIST_SEPARATOR = "|" -DEFAULT_BKPROP = ["id", "user", "userid", "by", "byid", "timestamp", "expiry", "reason", "range", "flags"] -DEFAULT_BKSHOW = ["account", "temp", "ip", "range"] - - -class WikipediaQuery(JSONQuery): - def __init__(self, params={}): - params.update({ - "action": "query", - "format": "json", - }) - JSONQuery.__init__(self, base_url=WIKIPEDIA_QUERY_BASE_URL, params=params) - - -class ListQuery(WikipediaQuery): - def __init__(self, list_name, params={}): - params.update({ - "list": list_name, - }) - WikipediaQuery.__init__(self, params) - - -class BlockQuery(ListQuery): - def __init__(self, bkprop=DEFAULT_BKPROP, bkshow=DEFAULT_BKSHOW, bkdir="newer", limit=500, continue_token=None): - params = { - "bkprop": LIST_SEPARATOR.join(bkprop), - "bkshow": LIST_SEPARATOR.join(bkshow), - "bkdir": bkdir, - "bklimit": limit, - } - - if continue_token is not None: - params.update({"bkcontinue": continue_token}) - - ListQuery.__init__(self, "blocks", params=params) - - diff --git a/banapedia/wapi/__init__.py b/banapedia/wapi/__init__.py deleted file mode 100644 index e69de29..0000000 -- cgit v1.2.3