Manual:Pywikibot/add text.py

From MediaWiki.org
Jump to navigation Jump to search
Git logo
Wikimedia Git repository has this file: scripts/add_text.py

This is a script which helps to add a text at the end of the page but above categories, interwiki and template for the stars of the interwiki (default setting), or add a text at the top of the page.

This needs Python with at least v2.4 (not v2.3) as stated on Manual:Pywikibot/Installation.

Parameters[edit]

These command line parameters can be used to specify which pages to work on:

-cat                Targets entries within a specific category
-page               Use a page as generator
-file               Read a list of pages to treat from the named text file. Page titles in the file must be 
                    enclosed with [[brackets]] or separated by newlines. Argument can also be given as "-file:filename".

Furthermore, the following command line parameters are supported:

-text               Define which text to add
-summary            Define the summary to use
-except             Use a regex to check if the text is already in the page *
-excepturl          Use the html page as text where you want to see if there's the text, not the wiki-page.
-newimages          Add text in the new images
-untagged           Add text in the images that don't have any license template
-always             If used, the bot won't ask if it should add the text specified
-up                 If used, put the text at the very top of the page *

For more command line parameters, run the bot help command for example: python pwb.py add_text -help | more

Example[edit]

Adding a template to specific pages[edit]

It will add the text "{{Documentation subpage}}" at the very top of the pages with "Category:Template documentation", except for those which already include it.

python pwb.py add_text -cat:template_documentation -text:"{{Documentation subpage}}" -except:"\{\{([Tt]emplate:|)[Dd]ocumentation [Ss]ubpage" -up
  • -cat:template_documentation : only target entries categorized in the page of "Category:Template documentation"
  • -text:"{{Documentation subpage}}" : add the template "{{Documentation subpage}}" (excluding the quotes)
    • To insert return code, use "\n". But, if you use "-up" option, it becomes invalid.
  • -except:"\{\{([Tt]emplate:|)[Dd]ocumentation [Ss]ubpage" : regex commands to exclude entries which have this template already in the page
  • -up : Put the text at the top of the page instead

Another example:

python pwb.py add_text -cat:catname -summary:"Bot: Adding a template" -text:"{{Something}}" -except:"\{\{([Tt]emplate:|)[Ss]omething" -up

Adding category to pages without any category[edit]

This is a real instance that is used on Wikipedia to put a template on a page without any category, because if there are any hidden categories, the page will be defined as categorized.

python pwb.py add_text -excepturl:"class='catlinks'>" -uncat -text:"{{Categorizzare}}" -except:"\{\{([Tt]emplate:|)[Cc]ategorizzare" -summary:"Bot: Aggiungo template Categorizzare"

Global arguments available

These options will override the configuration in user-config.py settings.

Global options
ParameterDescriptionConfig variable
- Read the bot's configuration data from directory given by PATH, instead of from the default directory.
-lang:xx mylang
-family:xyz family
-user:xyz usernames
-daemonize:xyz
-help
-log log
-log:xyz logfilename
-nolog
-maxlag maxlag
-putthrottle:n
-put_throttle:n
Set the minimum time (in seconds) the bot will wait between saving pages. put_throttle
-debug:item Enable the log file and include extensive debugging data for component "item" (for all components if the second form is used). debug_log
-verbose Have the bot provide additional console output that may be useful in debugging. verbose_output
-cosmeticchanges Toggles the cosmetic_changes setting made in config.py or user-config.py to its inverse and overrules it. All other settings and restrictions are untouched. cosmetic_changes
-simulate simulate
- You may use all given numeric config variables as option and modify it with command line.