User:Lalit97/Sandbox/My first Pywikibot tool
Pywikibot is a Python library and collection of tools that automate work on MediaWiki sites. Originally designed for Wikipedia, it is now used throughout the Wikimedia Foundation's projects and on many other MediaWiki wikis.
The project started in 2002 and is currently on core version 3.0. It features full API usage and is up-to-date with new MediaWiki features and a Pythonic package layout. But it also works with older installations of MediaWiki 1.19 or higher.
Pywikibot supports Microsoft Windows, OS X and Linux when used with a compatible version of Python. It should also work on any other operating system that has a compatible version of Python installed. To check whether you have Python installed and to find its version, just type "python" at the CMD or shell prompt. Python 2.7.4 or higher or Python 3.4 or higher is required to run the bot but 3.5 or higher is recommended.
The guide will teach you how to:
- Create a new tool
- Run a Python 3 WSGI webservice on Kubernetes
- Allow webservice visitors to authenticate via OAuth using their Wikimedia unified account
- Basic knowledge of Python
- Basic knowledge of SSH
- Basic knowledge of the Unix command line
- Familiarity with OAuth terminology would be nice but not required
Steps to completion
- Create a new tool account
- Create a basic Pywikibot webservice
- Add a configuration file
- Add support for OAuth authentication
Step 1: Create a new tool account
- Create a new tool account.
- For the examples in this tutorial,
<TOOL NAME>is used to indicate places where your unique tool name is used in another command.
- For the examples in this tutorial,
- SSH to login.tools.wmflabs.org.
- If your local username is different from your shell account name on Toolforge, you will need to include your Toolforge shell account name in your ssh command (i.e. <shell_username>@login.tools.wmflabs.org).
become <TOOL NAME>to change to the tool user.
Step 2: Create your Pywikibot Tool account
In addition to your own Toolforge account, you also need to create a Tool acoount for your Pywikibot tool.
- Navigate to the Create Tool Account page in the Toolforge admin console.
- Enter a Unique Tool Name for your tool account.
Do not prefix your tool name with
tools.as this prefix will cause errors.
Note: If you only recently received access to the tools project, you may get an error about appropriate credentials. Log out and back in to fix the issue.
Within a minute or two, Toolforge creates the Tool account and grants you access. If you were logged in through ssh when you created the Tool account, you must log off and log in again
Step 3: Access your Pywikibot tool
After you create your Pywikibot's tool account, you can log into your tool project with SSH.
$ ssh <unix shell username>@login.tools.wmflabs.org
From the command line, switch to your tool account:
You should see the command prompt change to:
Now, you can install Pywikibot.
Step 4: Install Pywikibot
Using your tool account, do the following:
- Use git to download Pywikibot:
git clone --recursive --branch stable https://gerrit.wikimedia.org/r/pywikibot/core.git pywikibot-core cd pywikibot-core
Set up your bot for selected wikis by running:
Choose a license
Pywikibot comes with an MIT LICENSE file. Make sure to choose a license for your tool early on. Also see, Help:Tool_Labs/Developing#Licensing_your_source_code
Set up a webpage for your tool
You can add webpage for your tool under http://tools.wmflabs.org/TOOLNAME. For example, http://tools.wmflabs.org/my-first-pywikibot-tool. Once you set up a webpage for your tool, the Tool list will link to it.
To set up webpage for you tool:
- Log in with your Tool account.
- Create a ~/public_html directory.
- Create ~/public_html/index.html.
- Start the web service:
$ webservice start
Communication and support
We communicate and provide support through several primary channels. Please reach out with questions and to join the conversation.
|Phabricator Workboard||#Cloud-Services||Task tracking and bug reporting|
|IRC Channel||#wikimedia-cloud connect||General discussion and support|
|Mailing List||cloud@||Information about ongoing initiatives, general discussion and support|
|Announcement emails||cloud-announce@||Information about critical changes (all messages mirrored to cloud@)|
|News wiki page||News||Information about major near-term plans|
|Cloud Services Blog||Clouds & Unicorns||Learning more details about some of our work|
|Wikimedia Technology Blog||techblog.wikimedia.org||News and stories from the Wikimedia technical movement|