From MythTV Official Wiki
Jump to: navigation, search

Important.png Note: The correct title of this article is It appears incorrectly here due to technical restrictions. is a pywikipedia script used to scan the entire site for a particular string, and substitute it with another. It intelligently only looks at real pages, not redirects, categories, or images. It only updates a page if there is a substitution.

Source code


import re, sys
from pywikipedia import wikipedia

oldtext = sys.argv[1]
newtext = sys.argv[2]

site = wikipedia.getSite()

for page in site.allpages():
        if not page.isCategory() and not page.isRedirectPage() and not page.isImage():
                wikitext = page.get()
                newtext = re.compile(oldtext).sub(newtext, wikitext)
                        if wikitext <> newtext:
                                page.put(newtext=newtext, \
                                        comment='[[pywikipedia]] assisted cleanup ([[]])-> replacing ' + \
                                        oldtext + ' with ' + newtext, minorEdit=True)
                except Exception:
                        print "Unable to edit " + page.aslink()


To run the script, it needs two arguments. (Use quotation marks to escape the shell).

% python "old text" "new text"

It will check every article, and if it contains "old text", it will replace it with "new text".