Pywikipediabot/category.py
From Meta, a Wikimedia project coordination wiki
Script which manages categories. This needs Python with at least v2.4 (not v2.3) as stated on Using the python wikipediabot.
Contents |
[edit] Syntax
The syntax is:
where action can be one of these:
* add - mass-add a category to a list of pages * remove - remove category tag from all pages in a category * move - move all pages in a category to another category * tidy - tidy up a category by moving its articles into subcategories * tree - show a tree of subcategories of a given category * listify - make a list of all of the articles that are in a category
and option can be one of these:
* -person - sort persons by their last name (for action 'add')
* -rebuild - reset the database
* -from: - The category to move from (for the move option)
Also, the category to remove from in the remove option
Also, the category to make a list of in the listify option
* -to: - The category to move to (for the move option)
- Also, the name of the list to make in the listify option
NOTE: If the category names have spaces in them you may need to use
a special syntax in your shell so that the names aren't treated as
separate parameters. For instance, in BASH, use single quotes,
e.g. -from:'Polar bears'
* -batch - Don't prompt to delete emptied categories (do it
automatically).
* -summary: - Pick a custom edit summary for the bot.
* -inplace - Use this flag to change categories in place rather than
rearranging them.
* -nodelsum - An option for remove, this specifies not to use the custom
edit summary as the deletion reason. Instead, it uses the
default deletion reason for the language, which is "Category
was disbanded" in English.
* -overwrite - An option for listify, this overwrites the current page with
the list even if something is already there.
* -showimages - An option for listify, this displays images rather than
linking them in the list.
* -talkpages - An option for listify, this outputs the links to talk pages
of the pages to be listified in addition to the pages
themselves.
* -recurse - Recurse through all subcategories of categories.
* -match - Only work on pages whose titles match the given regex (for
move and remove actions).
* -create - An option for add: if a page doesn't exist, do not skip it,
create it instead
If action is "add", the following options are supported:
¶ms;
For the actions tidy and tree, the bot will store the category structure locally in category.dump. This saves time and server load, but if it uses these data later, they may be outdated; use the -rebuild parameter in this case.
Or to do it all from the command-line,
[edit] Example
[edit] Adding category
If your list of pages is in a file, enter:
If you don't enter a filename, you will be prompted for a page that has the file list.
Follow the on-screen instructions - you will be prompted for the category name.
To create a new category from a list of persons, you will usually want them to be sorted alphabetically by last name (assuming Western surname conventions). E.g. Adding the "Artist" category to the page "Jane Smith", it would be added in the form [[Category:Artists|Smith, Jane]]. Type:
and follow the on-screen instructions.
[edit] Move category
If you want to move all pages in a category to another category, you could do the following:
You will be prompted for the old category (that you also want to keep but enter it)
Enter the name of the category without the 'Category:' prefix.
You will now be prompted for the new category, now enter the old and new Category like this:
To do it all from the command-line, use the following syntax:
For example, this syntax will move all pages in the category US to the category United States.
Global arguments available for all bots
| arg | Description | Default |
|---|---|---|
| -family:xyz | Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, commons, wikitravel, …. This will override the configuration in user-config.py settings. | user-config.py parameter: family |
| -lang:xx | Set the language of the wiki you want to work on, overriding the configuration in user-config.py where xx should be the language code[1]. | user-config.py parameter: mylang |
| -log | Enable the logfile. Logs will be stored in the logs subdirectory. | user-config.py parameter: log ? |
| -log:xyz | Enable the logfile, using xyz as the filename. | |
| -nolog | Disable the logfile (if it's enabled by default). | |
| -putthrottle:nn -pt:nn |
Set the minimum time (in seconds) the bot will wait between saving pages. | user-config.py parameter: putthrottle ? |
| -verbose -v |
Make the program output more detailed messages than usual to the standard output about its current work, or progress, while it is proceeding. This may be helpful when debugging or dealing with unusual situations. | not selected |