summaryrefslogtreecommitdiff
path: root/wikibania/wapi/WikipediaQuery.py
blob: 3f544b6cf539b95fc7adac67a6999785e829ac79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from ..api.Query import JSONQuery

WIKIPEDIA_QUERY_BASE_URL = "https://en.wikipedia.org/w/api.php"
LIST_SEPARATOR = "|"


class WikipediaQuery(JSONQuery):
    def __init__(self, params=None):
        if params is None:
            params = {}

        params.update({
            "action": "query",
            "format": "json",
        })
        super(WikipediaQuery, self).__init__(base_url=WIKIPEDIA_QUERY_BASE_URL, params=params)


class ListQuery(WikipediaQuery):
    def __init__(self, list_name, params=None):
        if params is None:
            params = {}

        params.update({
            "list": list_name,
        })
        super(ListQuery, self).__init__(params)


class BlockQuery(ListQuery):
    def __init__(self, properties=None, show=None, sort="newer", limit=500, continue_token=None):
        if properties is None:
            properties = []

        if show is None:
            show = []

        params = {
            "bkprop": LIST_SEPARATOR.join(properties),
            "bkshow": LIST_SEPARATOR.join(show),
            "bkdir": sort,
            "bklimit": limit,
        }

        if continue_token is not None:
            params.update({"bkcontinue": continue_token})

        super(BlockQuery, self).__init__("blocks", params=params)