Purple exclamation mark.svg Planning the future of Botwiki! - Help us bring Botwiki up to date, contribute to our strategy discussion, add bot scripts, and contribute manuals, guides, and tutorials! Almost anything related to bots, particularly those used to edit mediawiki, is welcome.

Red exclamation mark.svg UNABLE TO EDIT? - We've experienced attacks by spambots lately and now require you to confirm your e-mail before you can edit (go to your preferences, enter an e-mail address, and request a confirmation e-mail, then go to your e-mail and click on the confirmation link). We also require new accounts to make a few edits and wait a few minutes before before you can create a page; however, if this is a problem contact us in #botwiki and we can manually confirm your account. Sorry for the inconvenience.

Python:Movepages

From Botwiki
Jump to: navigation, search
import wikipedia, pagegenerators, os, re, sys, time, threading
 
""" Mass moving of pages via a file
 
The format for the file should be:
 
[[Oldpagename]] [[Newpagename]]
[[Anotheroldpage]] [[Anothernewpage]]
 
Each should be on it's own line"""
 
def main():
    site = wikipedia.getSite()
    name = wikipedia.input(u"What's the file's name: ")
    #moving = wikipedia.input(u"What's the summary for moving the pages? ")
    #gen = pagegenerators.TextfilePageGenerator(filename=name)
    try:
        FILE = open(name, 'r')
        for line in FILE:
            pattern = re.compile(r"\[\[(.*?)\]\]\s\[\[(.*?)\]\]")
            results = pattern.findall(line)
            if results != []:
                for result in results:
                    old = result[0]
                    now = result[1]
                    page = wikipedia.Page(site, old)
                    try:
                        text = page.get()
                        wikipedia.output(u"Moving %s to %s" % (old, now))
                        page.move(now, 'Moving...')                        
                    except wikipedia.BadTitle:
                        wikipedia.output(u"Bad title on %s, skipping" % page)
                        continue
                    except wikipedia.NoPage:
                        wikipedia.output(u"No page %s, skipping" % page)
                        continue                        
                    except wikipedia.Error:
                        wikipedia.output(u"Error on %s, skipping" % page)
                        continue               
 
    except wikipedia.Error:
        wikipedia.output(u"Error, skipping")
 
if __name__ == '__main__':
    try:
        main()
    finally:
        wikipedia.stopme()
Personal tools
Share