#!/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")