Chheh:Pywikibot/user-config.py

This page is a translated version of the page Manual:Pywikibot/user-config.py and the translation is 25% complete.
Outdated translations are marked like this.

Phòe-tì

Tī lí cháu jīm-hô thêng-sek chìn-chêng, lí ài tī bo̍k-lio̍k pywikibot lāi kiàn-li̍p tóng-àn user-config.py. Lí ū nn̄g chióng hong-sek kiàn-li̍p:

  1. Chhiú-tōng kiàn-li̍p tóng-àn. I chì-chió su-iàu nn̄g chì saⁿ ê piàn-sò͘ phòe-tì, mā ài hē tī chèng-khak ê ūi-tì.
  2. Tī command shell su-ji̍p python pwb.py generate_user_files.py lâi cháu kiàn-pún generate_user_files.py, che ē hām lí hō͘-tōng pēng sán-seng tóng-àn, pēng chûn tī ī-siat ê phòe-tì ūi-tì.

Ūi-tì

Pywikibot ē chiàu sūn-sī tī ē-kha ê ūi-tì chhōe user-config:

  • Specified via the -dir: argument (for example: -dir:/foo/bar)
  • The content of the environment variable PYWIKIBOT_DIR
  • The current directory
  • The directory in which the pwb.py file is
  • The .pywikibot directory in the application data directory (Windows) or home directory (that directory gets automatically created)

(Chham-oa̍t: get_base_dir())

Ē-kha sī chhiú-tōng pian-chi̍p tóng-àn ê chí-ín.

Phah-khui chi̍t ê bûn-pún pian-chi̍p-khì (pí-lūn Windows ê Notepad), kā bûn-pún tóng-àn user-config.py pó-chûn tī pywikibot chu-liāu-kiap lāi-té.

Nā-sī lí-ê gí-giân sú-iōng tio̍h hui-ASCII ê bûn-jī, lí tio̍h-ài ēng chhin-chhiūⁿ Notepad++ ê Unicode pian-chi̍p-khì, chiah pó-chûn lí-ê user-config (bô BOM hû-hō ê Unicode kái-má). M̄-thang bōe-kì-tit su-ji̍p

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

chò-ûi tē-it chōa.

Ka-thiam ē-kha kúi chōa khì tī user-config.py:

Code Kái-soeh
family = 'wikipedia'
mylang = 'en'

xx is the code for the language you are working on, for example 'en' is English.[1] Family is the project name.[2]

usernames['wikipedia']['en'] = 'ExampleBot'

Your user-config.py file needs to specify the bot's username.

In this example, the user is working on English Wikipedia, and has created a bot account with the username "ExampleBot". [3]

(Optional)

authenticate['*.wikipedia.org'] = ('<consumer_key>','<consumer_secret>', '<access_key>', '<access_secret>')

This replaces password-based authentication with OAuth, which is more secure (especially for bots with shared ownership). See Pywikibot/OAuth on how to obtain the keys/secrets.

(Optional)

usernames['wikipedia']['de'] = 'BeispielBot'
usernames['wikipedia']['en'] = 'ExampleBot'
usernames['wiktionary']['de'] = 'BeispielBot'

If you are working on more than one Wikimedia project, you can also add several usernames.

(Optional, and rarely needed)

console_encoding = 'utf-8'
textfile_encoding = 'unicode_escape'

If this is the encoding used by your system. Always try without first.

(Optional)

sort_ignore_case = True

Some scripts may use this for sorting, e.g. solve_disambiguation.py. Default is False. Capitalized titles will preceed uncapitalized ones if this key is False or omitted, and capitalization will be disregarded by sorting if True.

(Optional)

password_file = "user-password.py"

Define a password file. The lines of the file should be tuples in any of the following formats:

(code, family, username, password)
(family, username, password)
(username, password)

For BotPasswords, refer to Pywikibot/BotPasswords.

(Optional)
user_agent_description = "Description <contact@email.com>"
A free-form string that can be user to describe specific bot/tool, provide contact information, etc.

Now save user-config.py again.

user-config.py examples

EksempelBot on no.wikipedia

mylang = 'no'
usernames['wikipedia']['no'] = 'EksempelBot'

console_encoding = 'utf-8'
use_api_login = True

ExampleBot on Commons

mylang = 'commons'
family = 'commons'
usernames['commons']['commons'] = 'ExampleBot'

console_encoding = 'utf-8'
use_api_login = True

ExampleBot on Wikidata

mylang = 'wikidata'
family = 'wikidata'
usernames['wikidata']['wikidata'] = 'ExampleBot'

console_encoding = 'utf-8'
use_api_login = True

ExampleBot on Test wiki

mylang = 'test'
family = 'test'
usernames['test']['test'] = 'ExampleBot'

ExampleBot on Test2 wiki

mylang = 'test2'
family = 'wikipedia'
usernames['wikipedia']['test2'] = 'ExampleBot'

BeispielBot on de.wikipedia and de.wikibooks, with de.wikipedia as main wiki

mylang = 'de'
usernames['wikipedia']['de'] = 'BeispielBot'
usernames['wikibooks']['de'] = 'BeispielBot'

console_encoding = 'utf-8'
use_api_login = True

For non-Wikimedia wikis

See also

  • config.py (the source code of the module that loads and interpretes user-config.py)


Notes

  1. If you want to work with more than one language, choose the most common one. You can override this on the command line by using -lang:zh parameter.
  2. Meta uses 'meta' for both language code and wiki family, Commons uses 'commons' for both, and Testwiki uses 'test' for both, the multilingual wikisource uses '-' for the language. You can override this on the command line by using -family:wikibooks.
  3. Note that on Linux/Unix hosts username capitalization matters! While logging in may not be an issue, testing the log in or attempting to use a bot will not use the correct cookie file and may result in anonymous access to the API. This can cause problems for private wikis that do not allow anonymous access or use third party authentication. Default usernames for mediawiki and those pulled via LDAP or other third party authentication schemes will have an uppercase character for the first letter, thus 'user' becomes 'User'.


If you need more help on setting up your Pywikibot visit the #pywikibot IRC channel connect or pywikibot@ mailing list.