summaryrefslogtreecommitdiff
path: root/wikibania/wapi/WikipediaQuery.py
diff options
context:
space:
mode:
Diffstat (limited to 'wikibania/wapi/WikipediaQuery.py')
-rw-r--r--wikibania/wapi/WikipediaQuery.py48
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 @@
1from ..api.Query import JSONQuery
2
3WIKIPEDIA_QUERY_BASE_URL = "https://en.wikipedia.org/w/api.php"
4LIST_SEPARATOR = "|"
5
6
7class 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
19class 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
30class 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)