From 5e4f38688e4c14846b8264970a79c482c1ca7012 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 24 Oct 2014 01:45:28 +0200 Subject: Initial commit --- banapedia/wapi/WikipediaQuery.py | 42 ++++++++++++++++++++++++++++++++++++++++ banapedia/wapi/__init__.py | 1 + 2 files changed, 43 insertions(+) create mode 100644 banapedia/wapi/WikipediaQuery.py create mode 100644 banapedia/wapi/__init__.py (limited to 'banapedia/wapi') diff --git a/banapedia/wapi/WikipediaQuery.py b/banapedia/wapi/WikipediaQuery.py new file mode 100644 index 0000000..d3d2f94 --- /dev/null +++ b/banapedia/wapi/WikipediaQuery.py @@ -0,0 +1,42 @@ +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 new file mode 100644 index 0000000..a0f842f --- /dev/null +++ b/banapedia/wapi/__init__.py @@ -0,0 +1 @@ +__author__ = 'pacien' -- cgit v1.2.3