Kannada Language Workshop/Resources-PAWS
Pywikibot/PAWS Workshop Training Guide
editObjective
To equip participants with the knowledge and skills to automate tasks on Wikimedia projects using Pywikibot and PAWS.
Training Agenda
edit1. Introduction to Pywikibot
What is Pywikibot?
- A Python library and collection of tools designed for automating tasks on Wikimedia wikis.
- Benefits include saving time on repetitive edits, data processing, and reporting.
Why Use PAWS for Pywikibot?
- PAWS (Python A Web Service) is a cloud-based Jupyter Notebook environment for Wikimedia projects.
- Advantages:
- No local setup required.
- Easy access to Wikimedia API and Pywikibot library.
- Built-in collaboration and sharing options.
2. Setting Up Pywikibot
2.1 Installing and Configuring Pywikibot Locally (Optional)
- For local use, follow the Pywikibot Installation Guide.
- Requirements: Python 3.x, Git, and pip.
- Configuration steps:
- Clone the Pywikibot repository.
- Set up the
user-config.py
file.
2.2 Accessing PAWS
- Open PAWS at https://paws.wmcloud.org.
- Log in with your Wikimedia credentials.
- Select "New" → "Terminal" or "Python Notebook" to start.
2.3 Setting Up Pywikibot on PAWS
- Open a terminal in PAWS and navigate to your workspace directory.
- Clone the Pywikibot repository:
git clone https://gerrit.wikimedia.org/r/pywikibot/core pywikibot
- Navigate to the
pywikibot
folder:cd pywikibot
- Run the Pywikibot configuration script:
pwb.py generate_user_files
- Enter the required information, such as your Wikimedia username and the target wiki.
2.4 Logging In to Wikis
- Use the following command to log in:
pwb.py login
- Authenticate with your Wikimedia credentials to enable bot actions.
3. Common Pywikibot Scripts and Their Functions
- Basic Editing:
replace.py
: Finds and replaces text across multiple pages.
- Category Management:
add_text.py
: Adds content to pages in a specific category.category_redirect.py
: Manages category redirects. (Details)
- Data Processing:
- Explore the full list of scripts: Pywikibot Scripts.
4. Running Pywikibot Scripts on PAWS
4.1 Uploading Scripts
- Upload your custom Python scripts to your PAWS workspace using the upload option or dragging files into the file manager.
4.2 Executing Scripts
- Open a terminal in PAWS and navigate to the directory containing your script.
- Run the script with the following command:
pwb.py <script_name>
Replace
<script_name>
with the script you want to execute (e.g.,add_text
).
4.3 Viewing Results
- Monitor the terminal output for success messages or error logs.
- Verify changes directly on the target wiki.
5. Workshop Exercises
- Exercise 1: Editing a Page using add_text.py
- Edit a user sandbox page using
add_text.py
. - Verify the edit on the wiki.
- Edit a user sandbox page using
- Exercise 2: Replacing Text
- Use
replace.py
to change specific text across multiple pages.
- Use
- Exercise 3: Proofreading Category Pages
- Use a script to list pages in a specific category and validate their content.
6. Advanced Topics
- Creating Custom Scripts
- Write Python scripts to perform specific tasks by leveraging Pywikibot’s API.
- Use Pywikibot Documentation to explore its methods and modules.
7. Wrap-Up and Q&A
Summary of Key Takeaways:
- Pywikibot and PAWS streamline Wikimedia project contributions.
- Automating tasks saves time and ensures consistency.
Additional Resources for Continued Learning: