Jump to content

User:Ritchie333/badspeedies list.py

From Wikipedia, the free encyclopedia
# A pywikibot script to dump out all speedy deletion requests that still exist for all current admin candidates

import re
import pywikibot
from pywikibot import pagegenerators
import sys

length = 100000

reCSD = re.compile( '^Requesting speedy deletion \\(\\[\\[WP:CSD?#(.*)\\|CSD .*\\]\\]\\)\\.' )
reCandidate = re.compile( '^{{Admin election candidate\\|user=(.+)}}$')

def printspeedies( site, username ):
  user = pywikibot.User( site, username )
  for contrib in user.contributions( length ):
    title = contrib[ 0 ]
    timestamp = contrib[ 2 ]
    comment = contrib[ 3 ]
    if comment is not None:
      match = reCSD.match( comment )
      if match is not None:
        csd = match.group( 1 )
        print( str( csd ) + ' ' + str( title ) + ' ' + str( timestamp ) )

def main():
  site = pywikibot.Site()
  page = pywikibot.Page( site, 'Wikipedia:Administrator elections/October 2024/Candidates')
  for line in page.text.splitlines():
    match = reCandidate.match( line )
    if match is not None:
      username = match.group( 1 )
      print( '==' + username + '==' )
      printspeedies( site, username )

main()