-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
102 lines (78 loc) · 2.49 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import sys
import traceback
from datetime import datetime
import mwclient
import pymysql
from config import credentials, cttbot
from reports import Reports
def main(args):
wiki = args[1]
dry_run = False
methods = []
for arg in args[2:]:
if arg == "--dry-run":
dry_run = True
else:
methods.append(arg)
try:
for m in methods:
print(m)
run = Run(wiki, dry_run)
method = getattr(run, str(m))
if not method:
raise Exception("Method not implemented")
else:
method()
except Exception:
ts = datetime.now().replace(microsecond=0).isoformat()
print(ts + " ", end="", file=sys.stderr)
traceback.print_exc(file=sys.stderr)
sys.exit(1)
class Run:
def __init__(self, wiki, dry_run):
host = (
"127.0.0.1" if dry_run else wiki + "wiki.analytics.db.svc.wikimedia.cloud"
)
port = credentials.get("port", 3306)
self.db = pymysql.connect(
host=host,
user=credentials["user"],
passwd=credentials["pass"],
db=wiki + "wiki_p",
port=port,
)
self.site = mwclient.Site(wiki + ".wikipedia.org")
self.site.login(cttbot["user"], cttbot["pass"])
self.rep = Reports(self.site, self.db, wiki, dry_run)
def forgotten_articles(self):
self.rep.forgotten_articles()
def new_wikiprojects(self):
self.rep.new_wikiprojects()
def pagecountbynamespace(self):
self.rep.page_count_by_namespace()
def pages_with_most_revisions(self):
self.rep.pages_with_most_revisions()
def blank_pages(self):
self.rep.blank_pages()
def autopatrol_eligibles(self):
self.rep.autopatrol_eligibles()
def talk_pages_by_size(self):
self.rep.talk_pages_by_size()
def unused_file_redirects(self):
self.rep.unused_file_redirects()
def oldest_active(self):
self.rep.oldest_active()
def deleted_prods(self):
self.rep.deleted_prods()
def most_used_templates(self):
self.rep.most_used_templates()
def orphaned_talk(self):
self.rep.orphaned_talk()
def unused_templates(self):
self.rep.unused_templates()
def article_by_size(self):
self.rep.article_by_size()
def most_edited_page_last_month(self):
self.rep.most_edited_page_last_month()
if __name__ == "__main__":
main(sys.argv)