Wikia

WoWWiki

Watchlist Recent changes

Ralbot/addheader

< Ralbot

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='{{Help:Header}}'
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()

Pages on WoWWiki

94,214pages on
this wiki

Latest Photos

Add a Photo
55,641photos on this wiki
See more >

Recent Wiki Activity

See more >

Recent Questions

Around Wikia's network

Random Wiki