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 /wikibania/wapi/WikipediaQuery.py | |
parent | 16529a0d212e1387eacd590c0e5e1b1a13dc2641 (diff) | |
download | wikistats-bdf9099df8c2a4636b0ad0e710b73330877eef37.tar.gz |
Very cleaner, much class, such readable, wow
Diffstat (limited to 'wikibania/wapi/WikipediaQuery.py')
-rw-r--r-- | wikibania/wapi/WikipediaQuery.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/wikibania/wapi/WikipediaQuery.py b/wikibania/wapi/WikipediaQuery.py new file mode 100644 index 0000000..3f544b6 --- /dev/null +++ b/wikibania/wapi/WikipediaQuery.py | |||
@@ -0,0 +1,48 @@ | |||
1 | from ..api.Query import JSONQuery | ||
2 | |||
3 | WIKIPEDIA_QUERY_BASE_URL = "https://en.wikipedia.org/w/api.php" | ||
4 | LIST_SEPARATOR = "|" | ||
5 | |||
6 | |||
7 | class WikipediaQuery(JSONQuery): | ||
8 | def __init__(self, params=None): | ||
9 | if params is None: | ||
10 | params = {} | ||
11 | |||
12 | params.update({ | ||
13 | "action": "query", | ||
14 | "format": "json", | ||
15 | }) | ||
16 | super(WikipediaQuery, self).__init__(base_url=WIKIPEDIA_QUERY_BASE_URL, params=params) | ||
17 | |||
18 | |||
19 | class ListQuery(WikipediaQuery): | ||
20 | def __init__(self, list_name, params=None): | ||
21 | if params is None: | ||
22 | params = {} | ||
23 | |||
24 | params.update({ | ||
25 | "list": list_name, | ||
26 | }) | ||
27 | super(ListQuery, self).__init__(params) | ||
28 | |||
29 | |||
30 | class BlockQuery(ListQuery): | ||
31 | def __init__(self, properties=None, show=None, sort="newer", limit=500, continue_token=None): | ||
32 | if properties is None: | ||
33 | properties = [] | ||
34 | |||
35 | if show is None: | ||
36 | show = [] | ||
37 | |||
38 | params = { | ||
39 | "bkprop": LIST_SEPARATOR.join(properties), | ||
40 | "bkshow": LIST_SEPARATOR.join(show), | ||
41 | "bkdir": sort, | ||
42 | "bklimit": limit, | ||
43 | } | ||
44 | |||
45 | if continue_token is not None: | ||
46 | params.update({"bkcontinue": continue_token}) | ||
47 | |||
48 | super(BlockQuery, self).__init__("blocks", params=params) | ||