diff options
author | Pacien TRAN-GIRARD | 2014-10-24 18:05:48 +0000 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-10-24 18:05:48 +0000 |
commit | 4403fda939ef42aeffeccb343d74f3dc3b840f91 (patch) | |
tree | 63fd704f15f3030f1455aad0ef92403c5d093c70 /wikibania/wapi | |
parent | 16529a0d212e1387eacd590c0e5e1b1a13dc2641 (diff) | |
parent | bdf9099df8c2a4636b0ad0e710b73330877eef37 (diff) | |
download | wikistats-4403fda939ef42aeffeccb343d74f3dc3b840f91.tar.gz |
Merge branch 'refactor' into 'master'
Refactor
See merge request !1
Diffstat (limited to 'wikibania/wapi')
-rw-r--r-- | wikibania/wapi/WikipediaQuery.py | 48 | ||||
-rw-r--r-- | wikibania/wapi/__init__.py | 1 |
2 files changed, 49 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) | ||
diff --git a/wikibania/wapi/__init__.py b/wikibania/wapi/__init__.py new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/wikibania/wapi/__init__.py | |||
@@ -0,0 +1 @@ | |||
# | |||