WikiRobots/fr: Difference between revisions

From FreeCAD Documentation
(Created page with "Allez sur http://tools.wmflabs.org/pywikibot/ et téléchargez {{FileName|package/pywikipedia/core.zip}}. (le projet est aussi sous github, gerrit, etc... mais c'est un moyen...")
(Created page with "Décompressez le contenu dans le répertoire de votre choix.")
Line 24: Line 24:
Allez sur http://tools.wmflabs.org/pywikibot/ et téléchargez {{FileName|package/pywikipedia/core.zip}}. (le projet est aussi sous github, gerrit, etc... mais c'est un moyen simple d'obtenir un paquet complet et autonome).
Allez sur http://tools.wmflabs.org/pywikibot/ et téléchargez {{FileName|package/pywikipedia/core.zip}}. (le projet est aussi sous github, gerrit, etc... mais c'est un moyen simple d'obtenir un paquet complet et autonome).


Décompressez le contenu dans le répertoire de votre choix.
Unzip the content in your preferred directory.


Unless you want to install the libraries into your Python libs, you are done (if you still want to install them, check the file {{FileName|INSTALL}} in the base directory).
Unless you want to install the libraries into your Python libs, you are done (if you still want to install them, check the file {{FileName|INSTALL}} in the base directory).

Revision as of 21:18, 25 June 2021

Other languages:
Les robots sont intrinsèquement dangereux car ils peuvent automatiquement faire beaucoup de dégâts. Utilisez-les avec une extrême prudence!

Présentation

Les tâches répétitives peuvent être automatisées à l'aide de robots ou de bots, c'est-à-dire de programmes logiciels fonctionnant seuls sur le wiki.

Les robots classiques et les plus utilisés pour les sites wiki sont fournis par MediaWiki, sous le nom de paquet Pywikibot. Voir Manuel:Pywikibot pour des informations complètes.

En un mot, Pywikibot est une collection de scripts Python capables d'utiliser l'API wiki native pour agir sur les sites wiki. Pour voir la liste des API pour le wiki de FreeCAD, visitez http://www.freecadweb.org/wiki/api.php.

Pour utiliser Pywikibot, vous devez :

  1. installer le package Pywikibot
  2. configurez Pywikibot pour qu'il fonctionne sur le Wiki FreeCAD.
  3. lancez les scripts dont vous avez besoin pour la tâche à accomplir.

Il existe une multitude d'informations sur la façon d'installer, de configurer et d'utiliser Pywikibot. Cependant, soyez conscient que ces informations, bien qu'utiles, peuvent être trompeuses, car elles mélangent des instructions relatives à deux bases de code Pywikibot différentes et différentes versions de la collection de scripts Pywikibot.

Dans ce qui suit, vous trouverez les instructions de base pour configurer et utiliser Pywikibot sur le wiki FreeCAD. Cela vous permettra d'effectuer les tâches les plus courantes. Pour une utilisation avancée, référez-vous au Manuel:Pywikibot et au code source Python.

Installation

Allez sur http://tools.wmflabs.org/pywikibot/ et téléchargez package/pywikipedia/core.zip. (le projet est aussi sous github, gerrit, etc... mais c'est un moyen simple d'obtenir un paquet complet et autonome).

Décompressez le contenu dans le répertoire de votre choix.

Unless you want to install the libraries into your Python libs, you are done (if you still want to install them, check the file INSTALL in the base directory).

Pywikibot works with Python 2.6 and 2.7 with no issues. Python 3 has been not tested so far with FreeCAD wiki works as well.

Configuration

You must save the following Python code as a file with the name user-config.py in the base directory where you unzipped package/pywikipedia/core.zip (to be clear, in the same directory where you already find a file called user-config.py.sample).

# -*- coding: cp437  -*-
family = 'freecadwiki'
mylang = 'en'
usernames['freecadwiki']['en'] = u'<<yourWikiUserName>>'
#usernames['freecadwiki']['freecadwiki'] = u'<<yourWikiUserName>>'
console_encoding = 'cp437'

In the above code:

  • replace <<yourWikiUserName>> with your Wiki user name
  • replace cp437 with your console_encoding. To find out what is your console encoding, for Windows and Linux, launch the Python interpreter, enter import sys followed by print sys.stdout.encoding. Python will write your console_encoding on the screen.


Then you must save the following Python code as a file with the name freecadwiki_family.py under the sub-directory /pywikibot/families (together with the other family_xxx.py files).

# -*- coding: utf-8  -*-

__version__ = '$Id: 7f3891c3bbbfbd69c0b005de953514803d783d92 $'

from pywikibot import family


# The MediaWiki family
# user-config.py: usernames['mediawiki']['mediawiki'] = 'User name'
class Family(family.WikimediaFamily):
    def __init__(self):
        super(Family, self).__init__()
        self.name = 'freecadwiki'

        self.langs = {
            'en': 'www.freecadweb.org',
        }

    def scriptpath(self, code):
        return 'wiki'

    def path(self, code):
        return '/index.php' #The path of index.php, look at your wiki address. 
	 
    def apipath(self, code):
        return '/api.php' #The path of api.php

    def version(self, code):
        # Replace with the actual version being run on your wiki
        return '1.20.3'

    def protocol(self, code):
        """
        Can be overridden to return 'https'. Other protocols are not supported.
        """
        return 'http'
        #return 'https' # My server uses https

Usage

You are now all set to launch the Pywikibot scripts. The scripts themselves are contained in the /scripts subdirectory, from which you can know the names.

To launch the scripts, open a shell and move to the base directory (the installation one, NOT the /scripts subdirectory), and write

python pwb.py <<scriptname>>.py -<<parameter>>

where of course you replace <<scriptname>> with the name of the script you are interested in, and <<parameter>> with the parameter(s) required for the given script.

To have a description of the usage and parameters of any script, simply use the -help parameter. For instance, to have a description of the replace.py script (one of the most useful), type

python pwb.py replace.py -help

There is another very useful parameter, valid for all the scripts, called -simulate, that allows you to test commands without harming the Wiki. Use it, before going 'live'.

Examples

This command will log into the wiki

pwb.py login.py


This command will print a list of all the pages containing a link to SourceForge

pwb.py listpages.py -weblink:sourceforge.net


This command will replace all the links to the old SourceForge Forum with a link to the new freecadweb.org-hosted Forum

pwb.py replace.py -weblink:sourceforge.net/apps/phpbb/free-cad "sourceforge.net/apps/phpbb/free-cad" "forum.freecadweb.org"


This command will print a list of all the pages containing the word 'PartDesign', starting with the page titled "2d Drafting Module" and going on alphabetically

pwb.py listpages.py -start:"2d Drafting Module" -grep:PartDesign


This command will replace all the secure links to the old SourceForge Forum with a link to the new freecadweb.org-hosted Forum in the translated pages

pwb.py replace.py -start:Translations:! "https://sourceforge.net/apps/phpbb/free-cad" "http://forum.freecadweb.org"

FreeCAD Wiki Related Commands

Count all pages that a specific wiki templates is used in

python3 pwb.py templatecount -count GuiCommand


List all pages that a specific wiki templates is used in

python3 pwb.py templatecount -list GuiCommand

Replace a string in all the pages listed in the Arch category (a/k/a)

python3 pwb.py replace.py -cat:Arch