User:Stabbot/item value tweak.py

""" This bot will change a list of pages specified in the command line """
 * 1) -*- coding: utf-8  -*-

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

item_value_entry = re.compile (r'') armor_begin_info = re.compile (r'') armor_end_info = re.compile (r'')

def cleanup (text):

match = item_value_entry.search (text) if match: text = item_value_entry.sub (r'', text)

match1 = armor_begin_info.search (text) match2 = armor_end_info.search (text)

if match1 != None and match2 != None: intertext = text [match1.end:match2.start] intertext = intertext.strip

print 'Inter text = "' + intertext + '"'

if intertext == '': text = text[:match1.start] + text[match2.end:]

return text

def main : pages = [] reportit = False reportfile = None

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: removing item value section from armor box'}))

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) wikipedia.output ("Page: " + page.title ) 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