User:Misza13/browseCSD.py

From wikishia

This is a draft version of a pywikipedia script for assisting admins in the cleanup of the ever-backlogged CAT:CSD.

How it works:

  • For each page from CAT:CSD:
    • Get page's text and print it on user's screen
    • Ask if the page should be deleted
    • If the answer is positive:
      • Ask for a reason for deletion (shortcuts available)
      • Ask for confirmation
      • If confirmation is positive:
        • Delete the page
        • If it's not a talk page, check if there is one
        • If yes, ask if it should be deleted (under the standard G8 CSD)
#!/usr/bin/env python

import sys, os, time
sys.path.append(os.environ['HOME'] + '/pywikipedia')
import wikipedia, catlib, pagegenerators

rsnTrans = {
    'a7': 'Article does not assert the importance or significance of its subject. ([[WP:CSD#A7|CSD A7]])',
    'db-bio': 'An article about a real person, group of people, band, club, company, or web content that does not assert the importance or significance of its subject. ([[WP:CSD#A7|CSD A7]])',
    }

if __name__ == '__main__':
  try:
    Site = wikipedia.getSite()
    CSD = catlib.Category(Site,'Category:Candidates for speedy deletion')
    genCSD = pagegenerators.CategoryPartPageGenerator(CSD)
    for Page in genCSD:
      txt = Page.get()
      print '=' * 60
      print txt
      print '=' * 60
      choice = wikipedia.inputChoice('Delete page?',
          ['yes','no','stop'],['y','n','s'],default='n')
      if choice == 's': break
      if choice == 'y':
        confirm = 'n'
        reason = ''
        while confirm not in ['y','a']:
          reason = wikipedia.input('Reason for deletion?')
          if reason.lower() in rsnTrans.keys(): reason = rsnTrans[reason.lower()]
          confirm = wikipedia.inputChoice('Delete %s with reason "%s"?' % (Page, reason),
              ['yes','no','abort'],['y','n','a'],default='y')
        if confirm == 'y':
          Page.delete(reason,False)
          if not Page.isTalkPage():
            TalkPage = Page.switchTalkPage()
            if TalkPage.exists():
              del_talk = wikipedia.inputChoice('Delete associated talk page?',
                  ['yes','no'],['y','n'],default='y')
              if del_talk == 'y':
                TalkPage.delete('Orphaned talk page ([[WP:CSD#G8|WP:CSD G8]])',False)
              
  finally:
    wikipedia.stopme()