Non editing scripts#
listpages script#
Print a list of pages, as defined by page generator parameters
Optionally, it also prints page content to STDOUT or save it to a file in the current directory.
These parameters are supported to specify which pages titles to print:
- -format
(int|str) Defines the output format.
Can be a custom string according to python string.format() notation or can be selected by a number from the following list (1 is default format):
1 - '{num:4d} {page.title}'→ 10 PageTitle
2 - '{num:4d} [[{page.title}]]'→ 10 [[PageTitle]]
3 - '{page.title}'→ PageTitle
4 - '[[{page.title}]]'→ [[PageTitle]]
5 - '{num:4d} <<lightred>>{page.loc_title:<40}<<default>>'→ 10 localised_Namespace:PageTitle (colorised in lightred)
6 - '{num:4d} {page.loc_title:<40} {page.can_title:<40}'→ 10 localised_Namespace:PageTitle canonical_Namespace:PageTitle
7 - '{num:4d} {page.loc_title:<40} {page.trs_title:<40}'→ 10 localised_Namespace:PageTitle outputlang_Namespace:PageTitle
Important
Requires
outputlang:langset, see below.
numis the sequential number of the listed page.Hint
An empty format is equal to
-notitleand just shows the total number of pages.- -outputlang
[str] Language for translation of namespaces.
- -notitle
Page title is not printed.
- -get
Page content is printed.
- -tofile
(str) Save Page titles to a single file. File name can be set with
-tofile:filenameor-tofile:dir_name/filename.- -save
Save Page content to a file named as
page.title(as_filename=True). Directory can be set with-save:dir_name. If no dir is specified, current directory will be used.- -encode
(str) File encoding can be specified with
-encode:name(name must be a valid python encoding: utf-8, etc.). If not specified, it defaults toconfig.textfile_encoding.
- -put:
(str) Save the list to the defined page of the wiki. By default it does not overwrite an existing page.
- -overwrite
Overwrite the page if it exists. Can only be applied with -put.
- -summary:
(str) The summary text when the page is written. If it’s one word just containing letters, dashes and underscores it uses that as a translation key.
Custom format can be applied to the following items extrapolated from a page object:
- site
Obtained from
page._link._site.- title
Obtained from
page._link._title.- loc_title
Obtained from
page._link.canonical_title().- can_title
Obtained from
page._link.ns_title(). Based either the canonical namespace name or on the namespace name in the language specified by the-transparam; a default value******will be used if no ns is found.- onsite
Obtained from
pywikibot.Site(outputlang, self.site.family).- trs_title
Obtained from
page._link.ns_title(onsite=onsite). If selected, format requires trs_title,-outputlangmust be set.
This script supports use of pagegenerators arguments.
touch script#
This bot goes over multiple pages of a wiki, and edits them without changes
This is for example used to get category links in templates working.
Command-line arguments:
- -purge
Purge the page instead of touching it
Touch mode (default):
- -botflag
Force botflag in case of edits with changes.
Purge mode:
- -converttitles
Convert titles to other variants if necessary
- -forcelinkupdate
Update the links tables
- -forcerecursivelinkupdate
Update the links table, and update the links tables for any page that uses this page as a template
- -redirects
Automatically resolve redirects
This script supports use of pagegenerators arguments.