Badwiki.py
From MythTV Official Wiki
Revision as of 17:49, 5 February 2006 by Gregturn (talk | contribs) (Forked off into separate article underneath Category:Bot)
This is a pywikipedia script, developed to support maintenance of this site.
I want to thank a mysterious user (Special:Contributions/80.126.114.182) for finding some bad auto-wiki'd text. This is a modified version of changelink.py to replace one wiki string with an alternate string that is NOT wiki.
Source code
import re, sys from pywikipedia import wikipedia oldname = sys.argv[1] newname = sys.argv[2] site = wikipedia.getSite() page = wikipedia.Page(site=site, title=oldname) links = page.getReferences() print "There are a total of %s related articles that need to be updated" % len(links) for eachPage in links: wikitext = eachPage.get() newtext = re.compile("\[\[" + oldname + "\]\]").sub(newname, wikitext) try: eachPage.put(newtext=newtext, \ comment="[[pywikipedia]] assisted cleanup -> removing auto-wiki'd " + \ oldname + " with " + newname, minorEdit=True) except Exception: print "Unable to edit " +eachPage.aslink()
How to run it
To run the script, it needs two arguments. (Use quotation marks to escape the shell).
% python badwiki.py "Foo Bar" "FooBar"
It will find every article pointed at Foo Bar, substitue FooBar without wiki tags, and then write it as a minor edit. This also helps reduce the number of Special:Wantedpages.