-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrights-watcher.py
92 lines (70 loc) · 2.58 KB
/
rights-watcher.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Script de suivi des modifications de droits utilisateur sur Vikidia.
# (C) Linedwell, 2011-2018
#
# Distribué sous licence GNU GPLv3
# Distributed under the terms of the GNU GPLv3 license
# http://www.gnu.org/licenses/gpl.html
import sys
sys.path.insert(1, '..') #ajoute au PYTHONPATH le répertoire parent
import mylogging
from datetime import datetime
import pywikibot
import mailer
# Déclarations
sites = {
'fr' : pywikibot.Site('fr','vikidia'),
'it' : pywikibot.Site('it','vikidia'),
'de' : pywikibot.Site('de','vikidia'),
'en' : pywikibot.Site('en','vikidia'),
'es' : pywikibot.Site('es','vikidia'),
'ru' : pywikibot.Site('ru','vikidia'),
'ca' : pywikibot.Site('ca','vikidia'),
'eu' : pywikibot.Site('eu','vikidia'),
'scn' : pywikibot.Site('scn','vikidia'),
#'test' : pywikibot.Site('test','vikidia'),
'central' : pywikibot.Site('central','vikidia'),
}
### debug ###
for s in sites:
sites[s].login()
### end debug
#Recuperation des journaux de modification de droits "sensibles"
def rights_logs(end):
watched_rights = ["bureaucrat","sysop","nuker","abusefilter","bot","checkuser","oversight","developer"]
report = ""
for s in sites:
site = sites[s]
logevents = site.logevents(logtype="rights",end=end)
for le in logevents:
oldgroups = le.oldgroups
newgroups = le.newgroups
#Différence symétrique entre les deux listes, on regarde quels droits ont été retirés/ajoutés
diff = list(set(oldgroups).symmetric_difference(set(newgroups)))
# Si l'un des droits modifiés figure dans la liste des droits surveillés
if (set(diff).intersection(watched_rights)):
report += "[" + site.code + "][" + str(le.timestamp()) + "] " + le.user() + " -> " + le.page().title() + " (" + str(oldgroups) + " -> " + str(newgroups) + ")\n"
return report
#Envoie par mail le rapport de modification des droits
def mail_report(report):
if report != "":
#print report
mailer.send('[RW] Modification de droits sur Vikidia.',report)
#Exécution
def main():
last_check_file = 'rights-watcher.last'
bfile = open(last_check_file,'r')
last_check = bfile.read()
bfile.close()
report = rights_logs(last_check)
mail_report(report)
now = datetime.utcnow()
bfile = open(last_check_file,'w')
bfile.write(now.isoformat())
bfile.close()
if __name__ == "__main__":
try:
main()
finally:
pywikibot.stopme()