Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/spammerblocker.py
blob: 056c57e11402189fbe6a0b1b4382888984ef476a (plain)
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
#!/bin/env python3

import mwapi

host = "http://pe.sugarlabs.org/"
api_path = "wiki/api.php"

users = mwapi.MWApi( host, api_path )
users.login ("YOURUSER", "YOURPASS")
edittoken = users.get_tokens()['edittoken']

offset = None

while offset!=-1:

    print ("Here is a batch of users")
    result = users.get ( action="query",
                list="allusers",
                aulimit=50,
                auprop='editcount|registration',
                aufrom=offset)

    for user in result['query']['allusers']:
        print ("%s (%s edits) from %s" % 
                (user['name'], user['editcount'], user['registration']))
        
    print ('type users to not block, separated by comma')
    protected = input()
    protected = protected.split(',')

    print ('following users will be spared: ', protected)
    print ('block the rest (y/[n])?')
    response = input()

    offset = result['query-continue']['allusers']['aufrom']

    if response=='y':
        for user in result['query']['allusers']:
            if user['name'] not in protected:
                users.post ( action='block',
                        user=user['name'],
                        reason='Spammer blocker',
                        token=edittoken)

            print ("blocked " + user['name'])
        print ("\n\n")