Pywikibot/Setup: Difference between revisions
From charlesreid1
No edit summary |
|||
| Line 37: | Line 37: | ||
This will create a Site object corresponding to whichever site you have specified in your user-config.py file. | 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: | |||
<pre> | |||
python3 pwb.py login | |||
</pre> | |||
Now you can run the custom scripts (e.g., redirect) like this: | |||
<pre> | |||
python3 pwb.py redirect double | |||
</pre> | |||
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: | |||
<pre> | |||
python3 pwb.py beavo | |||
</pre> | |||
=Flags= | |||
[[Category:Pywikibot]] | [[Category:Pywikibot]] | ||
| Line 44: | Line 65: | ||
[[Category:MediaWiki]] | [[Category:MediaWiki]] | ||
[[Category:Python]] | [[Category:Python]] | ||
[[Category:Charlesreid1 | [[Category:Charlesreid1]] | ||
Revision as of 21:37, 31 January 2018
Setup
Install
Start by installing pywikibot. Recommended method is:
- git checkout the pywikibot repo
- python setup.py build
- python setup.py install
See Pywikibot.
Configure Site
To configure which site you want pywikibot to use, 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.
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