Manual:Pywikibot/pagefromfile.py

From mediawiki.org
This page is a translated version of the page Manual:Pywikibot/pagefromfile.py and the translation is 50% complete.

pagefromfile.pyはテキストファイルからウィキにページをアップロードするために使用されるPywikibot のスクリプトです。

このボットは、ウィキにアップロードする多数のページを含むUTF-8形式のテキストファイルから入力を取得します。 全てのページが重複せずに同じ開始・終了テキストを持たなくてはなりません。 開始・終了テキストは、既定ではページの内容とともにアップロードされることはありません。

ページ名は、既定では太字でマークされたページの内容の最初にあるテキスト部分('''と'''に囲まれた部分)から取得されます。 テキスト内にページのタイトルがない、あるいは違うマーカーによってマークされていると予期される場合、-titlestart-titleend、そして-notitleパラメータを使用してください。

固有の引数

パラメーター説明
-file:xxx The filename we are getting our material from, the default value is "dict.txt". Notice that if the source file name contains any space character, you should wrap it with double quotations (i.e. -file:"Page title").
-begin:xxx The text that marks the beginning of a page, the default value is "{{-start-}}"
-end:xxx The text that marks the end of the page, the default value is "{{-stop-}}"
-include Include the beginning and end markers to the page
-textonly Text is given without markers. Only one page text is given. -begin and -end options are ignored.
-titlestart:xxx The text used in place of ''' for identifying the beginning of a page title
-titleend:xxx The text used in place of ''' for identifying the end of the page title
-notitle Do not include the page title, including titlestart and titleend, to the page. Can be used to specify unique page title above the page content
-title:xxx The page title is given directly. Ignores -titlestart, -titleend and -notitle options
-nocontent:xxx If the existing page contains specified statement, the page is skipped from editing
-noredirect Do not upload on redirect pages
-summary:xxx The text used as an edit summary for the upload. If the page exists, standard messages for prepending, appending, or replacement are appended after it
-autosummary Use MediaWiki's autosummary when creating a new page, overrides -summary
-minor Set the minor edit flag on page edits
-showdiff Show difference between current page and page to upload, also forces the bot to ask for confirmation on every edit

If the page to be uploaded already exists, it is skipped by default. But you can override this behavior if you want to:


パラメーター説明
-appendtop Add the text to the top of the existing page
-appendbottom Add the text to the bottom of the existing page
-force Overwrite the existing page

It is possible to define a separator after the 'append' modes which is added between the existing and the new text. For example a parameter -appendtop:foo would add 'foo' between them. A new line can be added between them by specifying '\n' as a value.

基本的な例

最も基本的な形では、pagefromfileは複数のウィキページを含む単一のテキストファイルを入力として受け取ります。 例えば内容はこんな感じ:

{{-start-}}
'''Pywikibot''' は MediaWiki サイトでの作業を自動化する Python ライブラリとスクリプトの集まりです。
もともとはウィキペディアのために設計され、いまではウィキメディア財団のプロジェクト群全体および他のウィキでも使われています。
{{-stop-}}
{{-start-}}
'''AutoWikiBrowser'''(略称:'''AWB''')は、退屈・単調な編集をより速く容易にするために制作された、半自動MediaWikiエディターです。
{{-stop-}}

これを「pages.txt」のようなUTF-8でエンコードされたテキストファイルとして保存します。 それからpython pwb.py pagefromfile -showdiff -file:pages.txtを実行します。 このコマンドで、ボットはPywikibotAutoWikiBrowser—双方とも最初の'''太字'''の要素—を作成するでしょう。 -showdiffによって編集を保存する前に内容を確認することができます。

異なるページタイトル

最初の太字の要素が正しいページのタイトルとは限りません。 例えば、私たちはAutoWikiBrowserの記事を代わりにAWBに置こうとするかもしれません。 そのためには、各記事の前にトリプルクオートで挟まれた(要するに太字の)正しいページのタイトルが書かれた1行を追加します。

{{-start-}}
'''Pywikibot'''
'''Pywikibot''' は MediaWiki サイトでの作業を自動化する Python ライブラリとスクリプトの集まりです。
もともとはウィキペディアのために設計され、いまではウィキメディア財団のプロジェクト群全体および他のウィキでも使われています。
{{-stop-}}
{{-start-}}
'''AWB'''
'''AutoWikiBrowser'''(略称:'''AWB''')は、退屈・単調な編集をより速く容易にするために制作された、半自動MediaWikiエディターです。
{{-stop-}}

and add the -notitle parameter to the call, i.e.: python pwb.py pagefromfile -showdiff -file:pages.txt -notitle.


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

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