diff options
author | Pacien TRAN-GIRARD | 2014-10-24 01:45:28 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-10-24 01:45:28 +0200 |
commit | 5e4f38688e4c14846b8264970a79c482c1ca7012 (patch) | |
tree | 6d150aa8f26eed939aabc9de1db3239a46cb7e05 /banapedia/wapi/WikipediaQuery.py | |
download | wikistats-5e4f38688e4c14846b8264970a79c482c1ca7012.tar.gz |
Initial commit
Diffstat (limited to 'banapedia/wapi/WikipediaQuery.py')
-rw-r--r-- | banapedia/wapi/WikipediaQuery.py | 42 |
1 files changed, 42 insertions, 0 deletions
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 @@ | |||
1 | from ..api.Query import JSONQuery | ||
2 | |||
3 | __author__ = 'pacien' | ||
4 | |||
5 | WIKIPEDIA_QUERY_BASE_URL = "https://en.wikipedia.org/w/api.php" | ||
6 | LIST_SEPARATOR = "|" | ||
7 | DEFAULT_BKPROP = ["id", "user", "userid", "by", "byid", "timestamp", "expiry", "reason", "range", "flags"] | ||
8 | DEFAULT_BKSHOW = ["account", "temp", "ip", "range"] | ||
9 | |||
10 | |||
11 | class WikipediaQuery(JSONQuery): | ||
12 | def __init__(self, params={}): | ||
13 | params.update({ | ||
14 | "action": "query", | ||
15 | "format": "json", | ||
16 | }) | ||
17 | JSONQuery.__init__(self, base_url=WIKIPEDIA_QUERY_BASE_URL, params=params) | ||
18 | |||
19 | |||
20 | class ListQuery(WikipediaQuery): | ||
21 | def __init__(self, list_name, params={}): | ||
22 | params.update({ | ||
23 | "list": list_name, | ||
24 | }) | ||
25 | WikipediaQuery.__init__(self, params) | ||
26 | |||
27 | |||
28 | class BlockQuery(ListQuery): | ||
29 | def __init__(self, bkprop=DEFAULT_BKPROP, bkshow=DEFAULT_BKSHOW, bkdir="newer", limit=500, continue_token=None): | ||
30 | params = { | ||
31 | "bkprop": LIST_SEPARATOR.join(bkprop), | ||
32 | "bkshow": LIST_SEPARATOR.join(bkshow), | ||
33 | "bkdir": bkdir, | ||
34 | "bklimit": limit, | ||
35 | } | ||
36 | |||
37 | if continue_token is not None: | ||
38 | params.update({"bkcontinue": continue_token}) | ||
39 | |||
40 | ListQuery.__init__(self, "blocks", params=params) | ||
41 | |||
42 | |||