From bdf9099df8c2a4636b0ad0e710b73330877eef37 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 24 Oct 2014 19:59:05 +0200 Subject: Very cleaner, much class, such readable, wow --- wikibania/wapi/WikipediaQuery.py | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 wikibania/wapi/WikipediaQuery.py (limited to 'wikibania/wapi/WikipediaQuery.py') 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 @@ +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) -- cgit v1.2.3