User:Ritchie333/aceusers.py
Appearance
# A pywikibot script to dump out all users who can vote in the ArbCom 2017 elections
# Defined as any unblocked user who on 1 November 2017 00:00 UTC has at least 150 mainspace edits and 4 days' service
# Usage : python aceusers.py start_from output_file
import sys
from datetime import datetime
import pywikibot
from pywikibot.data import api
startfrom = sys.argv[1] or '!'
output = sys.argv[2]
out = open(output, 'w')
site = pywikibot.Site('en', 'wikipedia')
minEdits = 150
minDays = 4
cutOff = datetime(2017, 11, 1, 0, 0, 0)
augen = site._generator(api.ListGenerator, type_arg='allusers',
auprop='editcount|registration|blockinfo',
aufrom=startfrom,
auexcludegroup='bot',
auwitheditsonly=1)
for userprops in augen:
username = userprops['name'].encode('utf-8')
print username
editCount = int(userprops['editcount'])
if minEdits <= editCount:
indeffed = False
if 'blockexpiry' in userprops and userprops['blockexpiry'] == 'infinity':
indeffed = True
if not indeffed and userprops['registration']:
reg = datetime.strptime(userprops['registration'], '%Y-%m-%dT%H:%M:%SZ')
diff = cutOff - reg
if diff.days >= minDays:
ucgen = site._generator(api.ListGenerator,
type_arg='usercontribs',
ucuser=userprops['name'],
ucstart=cutOff,
ucprop='', namespaces=0,
total=minEdits)
if minEdits <= len(list(ucgen)):
print 'storing ' + username
out.write(username + '\n')