Manual:Pywikibot/revertbot.py

This page is a translated version of the page Manual:Pywikibot/revertbot.py and the translation is 17% complete.

revertbot.py is a Pywikibot script used to revert certain edits.

The script helps you clean up after your bot if it does undesirable things. It goes through your bot's list of contributions, from most recent to most ancient, and reverts the last revision your bot made on each page – provided, of course, that your bot made the most recent revision on the page.

It is therefore most effectively used immediately after you notice your bot has gone astray.

使用法

It is invoked by typing python pwb.py revertbot.

It should almost certainly not be run unattended, as it does not ask for permission to make changes. Its default – and unalterable – mode is just to automatically make changes.

The following command line parameters are supported:


パラメーター説明
-username Edits of which user need to be reverted. Default is bot's username (site.username())
-rollback Rollback edits instead of reverting them. Note that in rollback, no diff would be shown
-limit:num Use the last num contributions to be checked for revert. The default is 500

Users who want to customize the behaviour should subclass the BaseRevertBot and override its callback method. Here is a sample:

class myRevertBot(BaseRevertBot):

    '''Example revert bot.'''

    def callback(self, item):
        '''Sample callback function for 'private' revert bot.

        @param item: an item from user contributions
        @type item: dict
        @rtype: bool
        '''
        if 'top' in item:
            page = pywikibot.Page(self.site, item['title'])
            text = page.get(get_redirect=True)
            pattern = re.compile(r'\[\[.+?:.+?\..+?\]\]', re.UNICODE)
            return bool(pattern.search(text))
        return False


利用できるグローバル引数

以下のオプションを用いることで、user-config.py の設定を上書きすることができます。

グローバル オプション
パラメーター 説明 設定変数名
-dir:パス 既定のディレクトリではなく、PATH で指定されたディレクトリからボットの設定データを読み込みます。  
-config:ファイル The user config filename. Default is user-config.py. user-config.py
-lang:xx user-config.py の設定を上書きする形で、作業するウィキの言語を設定します。xx には設定する適切な言語コードに置き換えてください。 mylang
-family:xyz 作業するウィキのファミリーを設定します。xyz には wikipedia、wiktionary、wikitravel などを指定します。 This will override the configuration in user-config.py. family
-user:xyz 既定の利用者名ではなく、利用者 'xyz' としてログインします。 usernames
-daemonize:xyz 直ちにターミナルへ操作を返し、stdout と stderr をファイル xyz にリダイレクトします。これは stdin からの入力を必要としないボットのみで使用します。  
-help ヘルプ テキストを表示します。  
-log ログファイル (ファイル名は既定で「スクリプト名-bot.log」の形式になります) の出力を有効にします。ログは logs の下位ディレクトリに保存されます。 log
-log:xyz ファイル xyz へのログの出力を有効にします。xyz にはファイル名を指定します。 logfilename
-nolog ログ ファイルの出力を無効にします (既定で有効になっている場合)。  
-maxlag maxlag パラメータの秒数を新しく設定します。 データベース サーバーが遅延している間、ボットの編集を遅らせます。既定値は config.py で設定できます。 maxlag
-putthrottle:n
-pt:n
-put_throttle:n
ページを保存するまでの最小時間(秒)を設定します。 put_throttle
-debug:item
-debug
コンポーネント "item" の拡張デバッグデータをログファイルに出力します。item にはデバッグの対象を指定します。item を指定しない場合、すべてのコンポーネントが対象になります。 debug_log
-verbose
-v
デバッグに役立つ、より詳細なメッセージをコンソールに出力するようにします。 verbose_output
-cosmeticchanges
-cc
config.py あるいは user-config.py での cosmetic_changes 設定を逆にし、無効にします。 その他の設定や制限はそのまま使用されます。 cosmetic_changes
-simulate サーバーへの書き込みを無効にします。 これは、コードのテストやデバッグに有用です (このオプションを使用時、変更される内容は表示されますが、実際に変更されることはありません)。 simulate
-<設定変数>:n 任意の設定変数と数値をオプションとして使用し、それをコマンドラインで変更できるようにします。