summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/downloader/__init__.py37
-rw-r--r--src/interpreter/__init__.py10
2 files changed, 35 insertions, 12 deletions
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():
46 self.endpoint = endpoint 46 self.endpoint = endpoint
47 self.return_format = return_format 47 self.return_format = return_format
48 48
49 def get_recent_changes(self, namespace="(Main)"): 49 self.rcnamespaces = {
50 """
51 Get the url corresponding to the latest changes made to the wiki.
52 (https://www.mediawiki.org/wiki/API:Recentchanges)
53
54 The namespace is used to restrict the results to a certain level. It
55 can be (Main) which is the default one, "Wikipedia", "File" or
56 others. It will be converted to an int corresponding to the rcnamespace
57 parameter. See https://meta.wikimedia.org/wiki/Help:Namespace
58 """
59 rcnamespaces = {
60 "(Main)": "0", 50 "(Main)": "0",
61 "Talk": "1", 51 "Talk": "1",
62 "User talk": "2", 52 "User talk": "2",
@@ -88,11 +78,34 @@ class WikimediaAPI():
88 "Topic": "2600" 78 "Topic": "2600"
89 } 79 }
90 80
81 def get_recent_changes(self, namespace="(Main)", count=500):
82 """
83 Get the url corresponding to the latest changes made to the wiki.
84 (https://www.mediawiki.org/wiki/API:Recentchanges)
85
86 The namespace is used to restrict the results to a certain level. It
87 can be (Main) which is the default one, "Wikipedia", "File" or
88 others. It will be converted to an int corresponding to the rcnamespace
89 parameter. See https://meta.wikimedia.org/wiki/Help:Namespace
90 """
91
91 url_params = { 92 url_params = {
92 "action": "query", 93 "action": "query",
93 "list": "recentchanges", 94 "list": "recentchanges",
94 "format": self.return_format, 95 "format": self.return_format,
95 "rcnamespace": rcnamespaces[namespace], 96 "rcnamespace": self.rcnamespaces[namespace],
97 "rclimit": count
96 } 98 }
97 url_params_str = urllib.parse.urlencode(url_params) 99 url_params_str = urllib.parse.urlencode(url_params)
98 return urllib.parse.urljoin(self.endpoint, "?" + url_params_str) 100 return urllib.parse.urljoin(self.endpoint, "?" + url_params_str)
101
102
103class Wrapper():
104 """Class used to wrap the Downloader and WikimediaAPI classes"""
105 def __init__(self):
106 self.api = WikimediaAPI()
107 self.downloader = Downloader()
108
109 def download_recent_changes(self, namespace="(Main)", count=500):
110 url = self.api.get_recent_changes(namespace=namespace, count=count)
111 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 @@
1"""
2Module used to filter and add data to a dictionary/json string given from the
3Wikimedia API.
4"""
5
6
7class Interpreter():
8 """Class used to filter and add data to a dictionary/json string given from
9 the Wikimedia API"""
10