Manual:Pywikibot/login.py

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

login.py is the python program that logs the user running the pywikibot on to the system using the data that can be found in user-config.py .

ボットとしてのログイン

Bots provide specified result and as a consequence, they should not need the attention that other changes require. By having a specific user to run the bot software, the changes created in this way will be hidden on a typical recent changes screen. Bot status is given when a community is in favour with someone running a bot.


How it knows where to login

In the user-config.py file there are three components:

  1. the language: mylang
  1. the family: family - this indicates wiki name, including wikipedia or wiktionary
  1. the username: username - this can be any user but it should be a user who is registered to run as a bot.

In order to login to all the projects/languages mentioned in user-config.py, the option -all can be used, and if the same password is used throughout all these projects, it can be combined with -pass so that the program doesn't ask for a password for each site.

$ python pwb.py login -all -pass

will login on all projects in user-config.py, using the same password for all. For now, using -pass option is not supported. (T102477) You should use password file instead. Create file with text like '("en", "wikipedia", "User", "password")' (you can use more than one line). Then, insert in your user-config.py file 'password_file = "path_to_password_file"' line. After this Pywikibot should use data from this file when he need to login. You should make user-config.py and password file unreadable for others (chmod 600 user-config.py) before adding secrets to it.

ログアウト

$ python pwb.py login -logout

Login using OAuth

Pywikibot supports login using OAuth authentication instead of password. The OAuth feature needs the site with Extension:OAuth installed and configured properly. OAuth is more secure (passwords are not sent over the internet, can be invalidated at any time, and the permissions of the bot user can be restricted) and should generally be preferred over normal login. See Manual:Pywikibot/OAuth on how to use it (it does not involve login.py).

If for some reason you want to log your bot in as a multi-user OAuth app (not recommended, but e.g. older MediaWiki might not support owner-only apps), you can use login.py for that, with the option -oauth. The process contains the following steps:

  1. Log into meta as your bot account. Create an OAuth app at Special:OAuthConsumerRegistration/propose if it does not exist yet, and record the consumer key and secret. Until T323849 is resolved, only version 1.0a is supported
  1. Run python pwb.py login -oauth
  1. Input OAuth consumer key
  1. Input OAuth consumer secret
  1. Authenticate user via web browser. You may need to manually copy the url from the terminal if the web browser doesn't open up automatically.
  1. Input response query string to terminal when authentication succeeds.

例: oauth_verifier=xxx&oauth_token=yyy

  1. Copy and paste authentication entry generated into user-config.py .
-logout, -pass, -force, -pass:XXXX, -sysop は、-oauth と互換性がありません。


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

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