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 +++++++++++++++++++++++++------------ src/interpreter/__init__.py | 10 ++++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/interpreter/__init__.py (limited to 'src') 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) diff --git a/src/interpreter/__init__.py b/src/interpreter/__init__.py new file mode 100644 index 0000000..bf550ef --- /dev/null +++ b/src/interpreter/__init__.py @@ -0,0 +1,10 @@ +""" +Module used to filter and add data to a dictionary/json string given from the +Wikimedia API. +""" + + +class Interpreter(): + """Class used to filter and add data to a dictionary/json string given from + the Wikimedia API""" + -- cgit v1.2.3