summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/downloader/__init__.py37
1 files changed, 12 insertions, 25 deletions
diff --git a/src/downloader/__init__.py b/src/downloader/__init__.py
index 86ad6e6..15fba41 100644
--- a/src/downloader/__init__.py
+++ b/src/downloader/__init__.py
@@ -46,7 +46,17 @@ 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 self.rcnamespaces = { 49 def get_recent_changes(self, namespace="(Main)"):
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 = {
50 "(Main)": "0", 60 "(Main)": "0",
51 "Talk": "1", 61 "Talk": "1",
52 "User talk": "2", 62 "User talk": "2",
@@ -78,34 +88,11 @@ class WikimediaAPI():
78 "Topic": "2600" 88 "Topic": "2600"
79 } 89 }
80 90
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
92 url_params = { 91 url_params = {
93 "action": "query", 92 "action": "query",
94 "list": "recentchanges", 93 "list": "recentchanges",
95 "format": self.return_format, 94 "format": self.return_format,
96 "rcnamespace": self.rcnamespaces[namespace], 95 "rcnamespace": rcnamespaces[namespace],
97 "rclimit": count
98 } 96 }
99 url_params_str = urllib.parse.urlencode(url_params) 97 url_params_str = urllib.parse.urlencode(url_params)
100 return urllib.parse.urljoin(self.endpoint, "?" + url_params_str) 98 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)