Manual:Pywikipediabot/user-config.py
This page was moved from MetaWiki.
It probably requires cleanup – please feel free to help out. In addition, some links on the page may be red; respective pages might be found at Meta. Remove this template once cleanup is complete.
generate_user_files.py.Subversion repository of wikimedia has the file:
Pywikipediabot |
||||||
|---|---|---|---|---|---|---|
|
- If you need more help on setting up your pywikipediabot visit the irc channel #pywikipediabotconnect @ freenode server or pywikipediabot mailing list.
Contents |
Configuration [edit]
Before you run any of the programs, you need to create a file named user-config.py in your pywikipedia directory either one of two ways:
- Create the file manually (it needs at least two or three variables configured, see below) or
- run the script login.py by typing
python login.pyin the command line shell and hit ENTER (which will interactively generate the file in an interactive "wizard" style).
(Alternatively, user-config.py can be located in a directory specified with a -dir: argument when a pywikipedia script is called, or specified by the PYWIKIBOT_DIR environment variable, or in the directory where a script is run.)
Below are the instructions for editing manually the content of the file.
For Wikimedia projects [edit]
Open a text editor (e.g. Notepad in Windows) and save the text file as user-config.py, in the pywikipedia folder.
If your language uses non-ASCII characters, you should use a Unicode-aware editor such as Notepad++ and save your user-config with Unicode encoding without BOM marks. Don't forget to insert
# -*- coding: utf-8 -*-
into the first line.
Add the following lines to user-config.py:
| Code | Explanation |
family = 'wikipedia' mylang = 'en' |
xx is the code for the language code you are working on, "en" is English.[1] Family is the project name.[2] |
usernames['wikipedia']['en'] = u'ExampleBot' |
Your In this example, the user is working on English Wikipedia, and has created a bot account with the username "ExampleBot".[3] [4] |
|
(Optional) usernames['wikipedia']['de'] = u'BeispielBot' usernames['wikipedia']['en'] = u'ExampleBot' usernames['wiktionary']['de'] = u'BeispielBot' |
(Optional) If you are working on more than one Wikimedia project, you can also add several usernames. |
|
(Optional) console_encoding = 'utf-8' textfile_encoding = 'unicode_escape' |
(Optional, and rarely needed) If this is the encoding used by your system. Always try without first. |
|
(Optional) sort_ignore_case = True |
(Optional) 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. |
Now save user-config.py again.
For non-Wikimedia wikis [edit]
- Main Page: Manual:Pywikipediabot/Use on non-WMF wikis
Notes [edit]
- ↑ 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:zhparameter. - ↑ 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. - ↑ The 'u' in front of the username stands for Unicode. The 'u' is required if your username contains non-ASCII characters.
- ↑ 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'.