User:MordantMaenad/scripts/blockweaponry.py
Jump to navigation
Jump to search
Use at your own risk. Blue takes no responsibility for the outcomes of your use of this script.
import wikipedia
import userlib
import urllib2
import time
site = wikipedia.getSite('en', 'rationalwiki')
site.forceLogin()
url = 'http://rationalwiki.org/w/api.php?action=query&format=yaml&list=allusers&augroup=bureaucrat&aulimit=500'
opener = urllib2.build_opener()
infile = opener.open(url)
contents = infile.read()
users = []
for line in contents.splitlines(1):
if line[6:12] == 'name: ':
users.append(line[12:])
escapees = []
for user in users:
me = userlib.User(site, 'Blue2')
if me.isBlocked():
me.unblock(u'Oh no.')
user = user[:-1]
print '\nBlocking ' + user
toblock = userlib.User(site, user)
try:
toblock.block(u'30 seconds', u'NOBODY EXPECTS THE SPANISH INQUISITION!', anon=False) #duration, reason
#time.sleep(30)
except:
print '\n Problem blocking ' + user
escapees.append(user)
continue
if escapees != []:
co = wikipedia.input('Continue? [Y/N] ')
if co == u'y':
for escapee in escapees:
escapee = escapee[:-1]
print '\nBlocking ' + escapee
toblock = userlib.User(site, escapee)
toblock.block(u'30 seconds', u'Don\'nt try to escape, it will only be more painful.', anon=False)