Difference between revisions of "Free Software Directory:Participate/Using pywikibot"

From Free Software Directory
Jump to: navigation, search
(Created subpage.)
Line 1: Line 1:
This page should be merged to [[Free Software Directory:Pywikibot]].
You can also use [https://www.mediawiki.org/wiki/Manual:Pywikibot pywikibot] to work from the command line.
You can also use [https://www.mediawiki.org/wiki/Manual:Pywikibot pywikibot] to work from the command line.

Latest revision as of 05:18, 12 June 2018

This page should be merged to Free Software Directory:Pywikibot.

You can also use pywikibot to work from the command line.


Create and activate an "isolated" virtual environment only for pywikibot (might be optional).

$ virtualenv --python=python3 v
$ source v/bin/activate

Clone the project, install and setup the bot.

$ git clone "https://gerrit.wikimedia.org/r/pywikibot/core.git"; cd core
$ pip install -r "requirements.txt"
$ python generate_family_file.py
Please insert URL to wiki: http://directory.fsf.org/wiki/Main_Page
Please insert a short name: fsd
$ python3 pwb.py listpages -family:fsd -lang:en -debug -page:loomio -get

... Shows Loomio content.

Sample Python script to display the information from a given page

import os

import pywikibot
from pywikibot import config2

log = logging.getLogger(__name__)

class FSD(object):

    def __init__(self):
            'fsd', os.path.join(os.path.dirname(__file__),
        self.site = pywikibot.Site(code="en", fam="fsd")

    def get(self, title):
        p = pywikibot.Page(pywikibot.Link(title, self.site))
        for (template, params) in p.templatesWithParams():
            if template.title() == 'Template:Entry':
                return params


Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the page “GNU Free Documentation License”.

The copyright and license notices on this page only apply to the text on this page. Any software or copyright-licenses or other similar notices described in this text has its own copyright notice and license, which can usually be found in the distribution or license text itself.