Manual:Pywikibot/replace.py

Replace.py is part of the Pywikipedia bot framework.

This bot will make direct text replacements. It will retrieve information on which pages might need changes either from an XML dump or a text file, or only change a single page.

Local
You can run replace.py with the following parameters (for example, ).

Examples
If you want to change templates from the old syntax, e.g., to the new syntax, e.g., download an XML dump file (page table) from http://download.wikimedia.org, then use this command:

python replace.py -xml -regex "" ""

Note that the you can match patterns across more than one line:

python replace.py -regex -start:! "First line\nSecond line" ""

Replace.py can be used to insert or append text to a page (note the replacement text has an embedded new line):

python replace.py -regex '^(.*)$' "\1   > "

If you have a dump called foobar.xml and want to fix typos, e.g. Errror -> Error, use this:

python replace.py -xml:foobar.xml "Errror" "Error"

If you have a page called 'John Doe' and want to convert HTML tags to wiki syntax, use: python replace.py -page:John_Doe -fix:HTML

If you run the bot without arguments you will be prompted multiple times for replacements:

python replace.py -file:blah.txt

The script asks the user before modifying an article. It is recommended to double-check the result to be sure that the bot did not introduce errors (especially with misspelled words). It is possible to specify a set of articles with an external text file containing Wiki links :

plane vehicle train car

The bot is then called using something like :

python replace.py [global-arguments] -file:articles_list.txt "errror" "error"