From charlesreid1

Setup

Install

Start by installing pywikibot. Recommended method is:

  • git clone the pywikibot repo (see Pywikibot/Installing)
  • python setup.py build
  • python setup.py install

See Pywikibot.

Configure Site

See Pywikibot/Installing#Set_up_a_family_file for details about setting up a family file.

To log in to the wiki that is part of the new family you created, run the provided login script through the pwb.py script. From the pywikibot directory, run:

python3 pwb.py login

This will prompt you for a site URL, username, and password.

(Where do the credentials get stored???)

Once you log in, there will be a user-config.py file created. Copy this to whichever directory you wish to run pywikibot from.

This user-config.py file does not contain any sensitive information.

Error

If you don't have a user-config.py file and you try and import pywikibot,

import pywikibot

you'll see this RuntimeError:

RuntimeError: No user-config.py found in directory '/tmp'.
  Please check that user-config.py is stored in the correct location.
  Directory where user-config.py is searched is determined as follows:

    Return the directory in which user-specific information is stored.

    This is determined in the following order:
     1.  If the script was called with a -dir: argument, use the directory
         provided in this argument.
     2.  If the user has a PYWIKIBOT2_DIR environment variable, use the value
         of it.
     3.  If user-config is present in current directory, use the current
         directory.
     4.  If user-config is present in pwb.py directory, use that directory
     5.  Use (and if necessary create) a 'pywikibot' folder under
         'Application Data' or 'AppData\Roaming' (Windows) or
         '.pywikibot' directory (Unix and similar) under the user's home
         directory.

    Set PYWIKIBOT2_NO_USER_CONFIG=1 to disable loading user-config.py

    @param test_directory: Assume that a user config file exists in this
        directory. Used to test whether placing a user config file in this
        directory will cause it to be selected as the base directory.
    @type test_directory: str or None
    @rtype: unicode

Write/Run Scripts

Once you have your user config file in your working directory, you can start your script like this:

import pywikibot
s = pywikibot.Site()

This will create a Site object corresponding to whichever site you have specified in your user-config.py file.

Running Provided Scripts

If you only want to use the provided pywikibot scripts, you will still need to go through the above steps. The only difference is that you won't need to copy user-config.py anywhere.

Start by running the login script from the pywikibot directory:

python3 pwb.py login

Now you can run the custom scripts (e.g., redirect) like this:

python3 pwb.py redirect double

and if you wish to make your own scripts based on the templates provided, you can make a new script in the scripts directory (suppose we call it "beavo.py"), then run it like this:

python3 pwb.py beavo

Flags