-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminstats.py
executable file
·79 lines (62 loc) · 2.64 KB
/
adminstats.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
import pywikibot as pw
from datetime import date
from dateutil.relativedelta import relativedelta
hywiki = pw.Site('hy', 'wikipedia')
admins = []
gen = hywiki.allusers(group='sysop')
for user in gen:
if user['name'] != 'Abuse filter':
admins.append(pw.User(hywiki, user['name']))
print(admins)
six_months = date.today() + relativedelta(months=-6)
total = {}
nss = ['Հիմնական', 'Պատկեր', 'Կաղապար', 'Կատեգորիա', 'patrol']
logtyps = ['delete', 'block', 'abusefilter', 'rights', 'merge', 'protect', 'MediaWiki', 'contentmodel']
for admin in admins:
total[admin.username] = {}
cs = admin.contributions(end=str(six_months) + 'T00:00:00.000Z', total=0)
ls = admin.logevents(end=str(six_months) + 'T00:00:00.000Z', total=0)
for c in cs:
ns = c[0].namespace().custom_name
if ns == '':
ns = 'Հիմնական'
if ns in total[admin.username]:
total[admin.username][ns] += 1
else:
total[admin.username][ns] = 1
for l in ls:
if l.type() in total[admin.username]:
total[admin.username][l.type()] += 1
else:
total[admin.username][l.type()] = 1
def activities_table(title, activities, actTypes, num):
t = '{| class="wikitable sortable"\n'
t += '|-\n'
t += '!' + title + '!!' + '!!'.join(i.username for i in admins) + '\n'
for actType in actTypes:
line = [actType]
for i in range(len(admins)):
if actType in activities[admins[i].username]:
line.append(str(activities[admins[i].username][actType]))
else:
line.append(str(0))
t += '|-\n'
t += '|' + '||'.join(line) + '\n'
total = ['Ընդամենը']
for admin in admins:
activities[admin.username]['Ընդամենը'] = 0
for actType in actTypes:
if actType in activities[admin.username]:
activities[admin.username]['Ընդամենը'] += activities[admin.username][actType]
total.append(activities[admin.username]['Ընդամենը'])
t += '|-\n'
t += '|Ընդամենը||' + '||'.join(
['style="background: #33f85f;"|' + str(_) if _ >= num else 'style="background: #ff0000;"|' + str(_) for _ in
total[1:]]) + '\n'
t += '|}'
return t
editsTable = activities_table('Խմբագրումներ', total, nss, 50)
logsTable = activities_table('Գործողություն', total, logtyps, 25)
page = pw.Page(hywiki, 'Վիքիպեդիա:Ադմինիստրատոր/Վիճակագրություն')
page.text = editsTable + '\n\n' + logsTable
page.save(summary='թարմացում', botflag=False)