diff options
Diffstat (limited to 'src/downloader')
-rw-r--r-- | src/downloader/wikimedia.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/downloader/wikimedia.py b/src/downloader/wikimedia.py new file mode 100644 index 0000000..1905d0a --- /dev/null +++ b/src/downloader/wikimedia.py | |||
@@ -0,0 +1,29 @@ | |||
1 | """ | ||
2 | Module used to generate wikimedia API urls for several uses | ||
3 | """ | ||
4 | |||
5 | |||
6 | class WikimediaAPI(): | ||
7 | """ | ||
8 | Class used to generate wikimedia API urls for several uses | ||
9 | |||
10 | The endpoint for this project should be "http://en.wikipedia.org/w/api.php" | ||
11 | but can be other wiki api endpoint made with the Wikimedia software. | ||
12 | The return_format can be one of json, php, wddx, xml, yaml, raw, txt, dbg, | ||
13 | dump or none. | ||
14 | """ | ||
15 | def __init__(self, endpoint, return_format): | ||
16 | self.endpoint = endpoint | ||
17 | self.return_format = return_format | ||
18 | |||
19 | def get_recent_changes(self, namespace="(Main)"): | ||
20 | """ | ||
21 | Get the url corresponding to the latest changes made to the wiki. | ||
22 | (https://www.mediawiki.org/wiki/API:Recentchanges) | ||
23 | |||
24 | The namespace is used to restrict the results to a certain level. It | ||
25 | can be "(Main)" which is the default one, "Wikipedia", "File" or | ||
26 | others. See https://meta.wikimedia.org/wiki/Help:Namespace | ||
27 | """ | ||
28 | return self.base_url + "?action=query&list=recentchanges&format="\ | ||
29 | + self.return_format + "&namespace=" + namespace | ||