Framework utility scripts#
Folder which holds framework scripts.
Added in version 7.0.
Removed in version 9.4: preload_sites
script was removed (T348925).
pwb wrapper script#
Wrapper script to invoke pywikibot-based scripts
This wrapper script invokes script by its name in this search order:
Scripts listed in
user_script_paths
list inside your user config settings file (usuallyuser-config.py
) in the given order. Refer External Script Path Settings.User scripts residing in
scripts/userscripts
(directory mode only).Scripts residing in
scripts
folder (directory mode only).Maintenance scripts residing in
scripts/maintenance
(directory mode only).Site-package scripts (site-package only)
Framework scripts residing in
pywikibot/scripts
.
This wrapper script is able to invoke scripts even if the script name is misspelled. In directory mode it also checks package dependencies.
Run scripts with pywikibot in directory mode using:
python pwb.py <pwb options> <name_of_script> <options>
or run scripts with pywikibot installed as a site package using:
pwb <pwb options> <name_of_script> <options>
This wrapper script uses the package directory to store all user files, will fix up search paths so the package does not need to be installed, etc.
Currently, <pwb options>
are Global options. This can be used
for tests to set the default site (see T216825):
python pwb.py -lang:de bot_tests -v
See also
pwb
entry point
Changed in version 7.0: pwb wrapper was added to the Python site package lib.
Changed in version 7.7: pwb wrapper is able to set PYWIKIBOT_TEST_...
environment variables,
see Environment variables.
Changed in version 8.0: renamed to wrapper.py.
Changed in version 9.4: enable external scripts via entry points.
generate_family_file script#
This script generates a family file from a given URL
This script must be invoked with the pwb wrapper script/code entry point.
Usage:
pwb generate_family_file.py [<url>] [<name>] [<dointerwiki>] [<verify>]
Parameters are optional. They must be given consecutively but may be omitted if there is no successor parameter. The parameters are:
<url>: an url from where the family settings are loaded
<name>: the family name without "_family.py" tail.
<dointerwiki>: predefined answer (y|s|n) to add multiple site codes
<verify>: disable certificate validaton `(y|n)
Example:
pwb generate_family_file.py https://www.mywiki.bogus/wiki/Main_Page mywiki
This will create the file mywiki_family.py in families folder of your base directory.
Changed in version 7.0: moved to pywikibot.scripts folder; create family files in families folder of your base directory instead of pywikibot/families.
Changed in version 8.1: [s]trict can be given for <dointerwiki> parameter to ensure that sites are from the given domain.
Changed in version 8.4: If the url scheme is missing, https
will be used.
generate_user_files script#
Script to create user-config.py. Other file names are not supported
Changed in version 7.0: moved to pywikibot.scripts folder.
Changed in version 8.0: let user the choice which section to be copied. Also EXTERNAL EDITOR SETTINGS section can be copied.
login script#
Script to log the bot in to a wiki account
Suggestion is to make a special account to use for bot use only. Make sure this bot account is well known on your home wiki before using.
The following parameters are supported:
- -all
Try to log in on all sites where a username is defined in user config file (user-config.py).
- -logout
Log out of the current site. Combine with
-all
to log out of all sites, or with Global options-family
,-lang
or-site
to log out of a specific site.- -oauth
Generate OAuth authentication information.
Note
Need to copy OAuth tokens to your user config file manually. -logout is not compatible with -oauth.
- -autocreate
Auto-create an account using unified login when necessary.
Note
the global account must exist already before using this.
- -async
Run the bot in parallel tasks, only usefull together with
-all
option
Hint
Use Global options -code
, -family
or -site
to determine the site to login/logout.
If not given as parameter, the script will ask for your username and password (password entry will be hidden), log in to your home wiki using this combination, and store the resulting cookies (containing your password hash, so keep it secured!) in a file in the data subdirectory.
All scripts in this library will be looking for this cookie file and will use the login information if it is present.
To log out, throw away the *.lwp
file that is created in the data
subdirectory.
Changed in version 7.4: moved to pywikibot.scripts
folder
shell script#
Spawns an interactive Python shell and imports the pywikibot library
To exit the shell, type ctrl-D (Linux) or ctrl-Z (Windows)
or use the exit()
function.
The following local option is supported:
- -noimport
Do not import the pywikibot library. All other arguments are ignored in this case.
Usage:
python pwb.py shell [args]
Changed in version 7.0: moved to pywikibot.scripts
version script#
Script to determine the Pywikibot version (tag, revision and date)
The following option is supported:
- -nouser
do not print usernames; otherwise they are printed for each registered family
Changed in version 7.0: version script was moved to the framework scripts folder
Added in version 9.1.2: the -nouser option.