WikiRobots: Difference between revisions

From FreeCAD Documentation
(Installation and configuration)
(→‎Configuration: - correct use of the {{Code}} template)
Line 33: Line 33:
You must save the following Python code as a file with the name {{FileName|user-config.py}} in the base directory where you unzipped {{FileName|package/pywikipedia/core.zip}} (to be clear, in the same directory where you already find a file called {{FileName|user-config.py.sample}}).
You must save the following Python code as a file with the name {{FileName|user-config.py}} in the base directory where you unzipped {{FileName|package/pywikipedia/core.zip}} (to be clear, in the same directory where you already find a file called {{FileName|user-config.py.sample}}).


{{Code|
{{Code|code=
# -*- coding: cp437 -*-
# -*- coding: cp437 -*-
family = 'freecadwiki'
family = 'freecadwiki'
Line 50: Line 50:
Then you must save the following Python code as a file with the name {{FileName|freecadwiki_family.py}} under the sub-directory {{FileName|pywikibot/families}} (together with the other {{FileName|family_xxx.py}} files).
Then you must save the following Python code as a file with the name {{FileName|freecadwiki_family.py}} under the sub-directory {{FileName|pywikibot/families}} (together with the other {{FileName|family_xxx.py}} files).


{{Code|
{{Code|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-



Revision as of 23:12, 8 November 2013

Robots are intrinsically dangerous as they can automatically do a lot of damage. Use with extreme care!

Overview

Repetitive tasks can be automated using Robots, i.e. software programs operating on the Wiki.

The natural and most used Robots for Wiki sites are provided by Wikipedia, under the name of Pywikibot.

In a nutshell, the Pywikibot is a collection of Python scripts able to use the native Wiki API to act on the Wiki sites (to see for instance the API list for FreeCAD Wiki, select this link http://www.freecadweb.org/wiki/api.php).

In order to use the Pywikibot, you need to:

  1. install the Pywikibot
  2. configure the Pywikibot to work on the FreeCAD Wiki
  3. launch the script(s) you need for the task at hand

There is a wealth of information on how to install, configure and use the Pywikibot. However, please be aware that this information, although useful, can be highly misleading, since it is mixing instructions related to two different Pywikibot codebases, and different versions of the Pywikibot scripts collection.

In the following, you will find the basic instructions to set up and use Pywikibot on FreeCAD wiki. This will allow you to perform most of the tasks. For more detailed information and advanced usage, you'll have eventually to refer to the Pywikibot manual and, even better, to the Python source code / source code comments.

Installation

Go to http://tools.wmflabs.org/pywikibot/ and download package/pywikipedia/core.zip (the project is also under github, gerrit, etc. but this is a simple way to get a full self-contained package).

Unzip the content in your preferred directory.

Unless you want to install the libraries into your Python libs, you are done.

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

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