User:Stabbot/cleanup template.py

""" STUB
 * 1) -*- coding: utf-8  -*-

Run as:

% python2.4 STUB -pages:PAGESFILE

Where PAGESFILE is the name of a text file containing a list of skills, one skill on each line, comments starting with '# ' (minus quotes), no blank lines. """

from __future__ import generators import sys, re, time import wikipedia, pagegenerators, config

def cleanup (text): #STUB return text

def main : pages = [] for arg in wikipedia.handleArgs : if arg.startswith ('-pages'): f = file (arg[7:], 'r') pages = [page.strip for page in f.readlines  if not page.startswith ('# ')] f.close else: pages.append (arg)

pages = [wikipedia.Page (wikipedia.getSite, title) for title in pages] wikipedia.setAction(wikipedia.translate(wikipedia.getSite, {'en': u'Robot: STUB'}))

doAll = False choice = 'n'

gen = iter(pages) pregen = pagegenerators.PreloadingGenerator (gen, pageNumber = 20)

for page in pregen: try: text = page.get if not page.canBeEdited : wikipedia.output (u'Skipping locked page %s' % page.title ) continue except wikipedia.NoPage: wikipedia.output (u'Page %s not found' % page.title ) continue except wikipedia.IsRedirectPage: text = page.get(get_redirect=True)

repText = cleanup (text)

if repText == text: print "Nothing to be done for: " + page.title else: wikipedia.showDiff(text, repText)

if not doAll: choice = wikipedia.inputChoice (u'Commit?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N') if choice in ['a', 'A']: doAll = True if doAll or choice in ['y', 'Y']: page.put (repText)

if __name__ == "__main__": try: main finally: wikipedia.stopme