Robot Wiki

From FreeCAD Documentation
Revision as of 17:17, 24 November 2021 by Kaktus (talk | contribs) (Created page with "==Użycie==")
Roboty są z natury niebezpieczne, ponieważ mogą automatycznie wyrządzić wiele szkód. Używaj ich z najwyższą ostrożnością!

Informacje ogólne

Powtarzalne zadania mogą być zautomatyzowane za pomocą robotów lub botów, czyli programów komputerowych działających samodzielnie na wiki.

Naturalne i najczęściej używane roboty dla stron wiki są dostarczane przez MediaWiki, pod nazwą pakietu Pywikibot. Zobacz Manual:Pywikibot, aby uzyskać pełne informacje.

W skrócie, Pywikibot jest zbiorem skryptów Pythona zdolnych do używania natywnego API wiki do działania na stronach wiki. Aby zobaczyć listę API dla FreeCAD wiki, odwiedź http://www.freecadweb.org/wiki/api.php.

Aby korzystać z Pywikibota, należy:

  1. zainstaluj pakiet Pywikibot
  2. skonfiguruj Pywikibota do pracy na FreeCAD Wiki
  3. uruchom skrypty potrzebne do wykonania danego zadania

Istnieje wiele informacji o tym jak zainstalować, skonfigurować i używać Pywikibota. Należy jednak pamiętać, że informacje te, choć przydatne, mogą być mylące, ponieważ mieszają instrukcje dotyczące dwóch różnych baz kodu Pywikibota i różnych wersji kolekcji skryptów Pywikibota.

Poniżej znajdziesz podstawowe instrukcje, jak skonfigurować i używać Pywikibota na wiki FreeCAD. Pozwoli Ci to na wykonywanie najczęstszych zadań. W celu uzyskania bardziej zaawansowanych informacji należy zapoznać się z Manual:Pywikibot oraz z kodem źródłowym w środowisku Python.

Instalacja

Wejdź na stronę http://tools.wmflabs.org/pywikibot/ i pobierz package/pywikipedia/core.zip (projekt jest również na githubie, gerrit, itp., ale jest to prosty sposób, aby uzyskać pełny, samodzielny pakiet).

Rozpakuj zawartość w wybranym przez siebie katalogu.

Jeśli nie chcesz zainstalować bibliotek w lokalizacji swoich bibliotek Python, to już po wszystkim (jeśli nadal chcesz je zainstalować, sprawdź plik INSTALL w katalogu bazowym).

Pywikibot działa ze środowiskiem Python v2.6 i v2.7 bez żadnych problemów. Python 3 nie był testowany do tej pory z FreeCAD wiki działa równie dobrze.

Konfiguracja

Musisz zapisać poniższy kod Pythona jako plik o nazwie user-config.py w katalogu bazowym, w którym rozpakowałeś package/pywikipedia/core.zip (dla jasności, w tym samym katalogu, w którym znajdziesz już plik o nazwie user-config.py.sample).

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

W powyższym kodzie:

  • zamień <<yourWikiUserName>> na nazwę użytkownika Wiki
  • zastąp cp437 swoim console_encoding. Aby dowiedzieć się, jakie jest kodowanie twojej konsoli, w systemach Windows i Linux uruchom interpreter Pythona, wpisz import sys, a następnie print sys.stdout.encoding. Python wyświetli twoje console_encoding na ekranie.


Następnie musisz zapisać poniższy kod Pythona jako plik o nazwie freecadwiki_family.py w podkatalogu /pywikibot/families (razem z innymi plikami family_xxx.py).

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

__version__ = '$Id: 7f3891c3bbbfbd69c0b005de953514803d783d92 $'

z pywikibot zaimportuj rodzinę


# 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

Użycie

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