-
Notifications
You must be signed in to change notification settings - Fork 8
/
usage_report.py
executable file
·61 lines (44 loc) · 1.3 KB
/
usage_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env python
from __future__ import unicode_literals
import mwclient
from theobot import password
from theobot import bot
# CC-BY-SA Theopolisme
class TemplateUsage(object):
"""Given a template name, creates an object with
data about its usage.
>>> tu = TemplateUsage("Template:RailGauge")
Example row from tu.csv():
[ID, NAMESPACE, PAGENAME, PARAM1, OTHERPARAMS, REDIRECTFROM]
"7865", "0", "Indian Railways", "1676mm", "", ""
"""
def __init__(self,template):
self.template = site.Pages[template]
def get(self):
"""Starts all of the necessary functions to get the
usage data"""
self._redirects()
self.usagedata = self._getusagedata()
def _redirects(self):
"""Stores all of the redirects to the template
(as well as original template name) to
self.template_redirects
"""
return True
def _getusagedata(self,page):
"""Given a page object returns a list of lists
with usage data. Each transclusion is its own
item in the list.
[TRANSCLUSION1, TRANSCLUSION2]
"""
def csv(self,file):
"""Saves a CSV to a given file with the template usage,
where each row represents a transclusion.
"""
return True
print "Powered on."
global site
site = mwclient.Site('en.wikipedia.org')
site.login(password.username, password.password)
if __name__ == '__main__':
main()