From 1ae5575c25242c538d30bd303092f99b9e78b716 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 22 Oct 2014 10:12:16 +0200 Subject: Adding Wrapper class in downloader module + beginning of interpreter module --- src/downloader/__init__.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/downloader') diff --git a/src/downloader/__init__.py b/src/downloader/__init__.py index 15fba41..86ad6e6 100644 --- a/src/downloader/__init__.py +++ b/src/downloader/__init__.py @@ -46,17 +46,7 @@ class WikimediaAPI(): self.endpoint = endpoint self.return_format = return_format - def get_recent_changes(self, namespace="(Main)"): - """ - Get the url corresponding to the latest changes made to the wiki. - (https://www.mediawiki.org/wiki/API:Recentchanges) - - The namespace is used to restrict the results to a certain level. It - can be (Main) which is the default one, "Wikipedia", "File" or - others. It will be converted to an int corresponding to the rcnamespace - parameter. See https://meta.wikimedia.org/wiki/Help:Namespace - """ - rcnamespaces = { + self.rcnamespaces = { "(Main)": "0", "Talk": "1", "User talk": "2", @@ -88,11 +78,34 @@ class WikimediaAPI(): "Topic": "2600" } + def get_recent_changes(self, namespace="(Main)", count=500): + """ + Get the url corresponding to the latest changes made to the wiki. + (https://www.mediawiki.org/wiki/API:Recentchanges) + + The namespace is used to restrict the results to a certain level. It + can be (Main) which is the default one, "Wikipedia", "File" or + others. It will be converted to an int corresponding to the rcnamespace + parameter. See https://meta.wikimedia.org/wiki/Help:Namespace + """ + url_params = { "action": "query", "list": "recentchanges", "format": self.return_format, - "rcnamespace": rcnamespaces[namespace], + "rcnamespace": self.rcnamespaces[namespace], + "rclimit": count } url_params_str = urllib.parse.urlencode(url_params) return urllib.parse.urljoin(self.endpoint, "?" + url_params_str) + + +class Wrapper(): + """Class used to wrap the Downloader and WikimediaAPI classes""" + def __init__(self): + self.api = WikimediaAPI() + self.downloader = Downloader() + + def download_recent_changes(self, namespace="(Main)", count=500): + url = self.api.get_recent_changes(namespace=namespace, count=count) + return self.downloader.download(url) -- cgit v1.2.3