Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/spammerblocker.py
diff options
context:
space:
mode:
Diffstat (limited to 'spammerblocker.py')
-rw-r--r--spammerblocker.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/spammerblocker.py b/spammerblocker.py
new file mode 100644
index 0000000..056c57e
--- /dev/null
+++ b/spammerblocker.py
@@ -0,0 +1,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")