Manual:Pywikibot/add_text.py

This page is a translated version of the page Manual:Pywikibot/add text.py and the translation is 16% complete.

This is a script which helps to add a text at the end of the page but above categories, interwiki and template for the stars of the interwiki (default setting), or add a text at the top of the page.

This needs Python with at least v2.7 as stated on Manual:Pywikibot/インストール .

パラメーター

These command line parameters can be used to specify which pages to work on:

-cat Targets entries within a specific category
-page Use a page as generator
-file Read a list of pages to treat from the named text file. Page titles in the file must be enclosed with brackets or separated by newlines. Argument can also be given as "-file:filename".

Furthermore, the following command line parameters are supported:

-text Define which text to add
-talkpage Put the text onto the talk page instead
-summary Define the summary to use
-except Use a regex to check if the text is already in the page **DEPRECATED IN 6.3.0 - Use "-grepnot" instead**
-excepturl Use the html page as text where you want to see if there's the text, not the wiki-page.
-newimages Add text in the new images
-untagged Add text in the images that don't have any license template
-always If used, the bot won't ask if it should add the text specified
-up If used, put the text at the very top of the page *
-noreorder Disable reordering of categories

For more command line parameters, run the bot help command for example: python pwb.py add_text -help | more

Adding a template to specific pages

It will add the text "{{Documentation subpage}}" at the very top of the pages with "Category:Template documentation", except for those which already include it.

$ python pwb.py add_text -cat:template_documentation -text:"{{Documentation subpage}}" -grepnot:"\{\{([Tt]emplate:|)(\s|)[Dd]ocumentation [Ss]ubpage" -up
  • -cat:template_documentationonly target entries categorized in the page of "Category:Template documentation"
  • -text:"{{Documentation subpage}}"add the template "{{Documentation subpage}}" (excluding the quotes)
    • To insert return code, use "\n". But, if you use "-up" option, it becomes invalid.
  • -grepnot:"\{\{([Tt]emplate:|)(\s|)[Dd]ocumentation [Ss]ubpage"regex commands to exclude entries which have this template already in the page
  • -upput the text at the top of the page instead

Another example:

$ python pwb.py add_text -cat:catname -summary:"Bot: Adding a template" -text:"{{Something}}" -grepnot:"\{\{([Tt]emplate:|)(\s|)[Ss]omething" -up


Adding category to pages without any category

This is a real instance that is used on Wikipedia to put a template on a page without any category, because if there are any hidden categories, the page will be defined as categorized.

$ python pwb.py add_text -excepturl:"class='catlinks'>" -uncat -text:"{{Categorizzare}}" -grepnot:"\{\{([Tt]emplate:|)[Cc]ategorizzare" -summary:"Bot: Aggiungo template Categorizzare"


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

以下のオプションを用いることで、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 任意の設定変数と数値をオプションとして使用し、それをコマンドラインで変更できるようにします。