User:Ralbot/addheader

This is my first little simple script to add the Help:Header template to a bunch of pages in the Help category. Sure it took me much more time to learn python and write this then it would have been to just add the header file manually, but at least now I know python and future scripts will take me much less time to write.

import sys import wikipedia import login import catlib import re

s=wikipedia.Site('en') for arg in sys.argv[1:]: wikipedia.argHandler(arg, 'sandbox')

test = catlib.Category(s, 'Category:Help') list = test.articles(recurse = False) pattern='' for catPage in list: text = catPage.get result = re.search(pattern, text) if result == None: print 'Header file not found for ', catPage choice = wikipedia.input('Do you want to add the header? ([y]Yes, [n]No, [a]Abort, [p]Print)') if choice == 'p': print text; choice = wikipedia.input('Do you want to add the header? ([y]Yes, [n]No, [a]Abort)') if choice == 'a': break if choice == 'y': catPage.put(pattern + '\n' + text, 'Bot: Added Help:Header to page') else: print 'Header file already exists for', catPage

wikipedia.stopme