Several methods to use multiple bot accounts

Due to T71283 sysop account setting was given up with release 3.0.20200111. On the other hand you may have multiple bot accounts, e.g. onw for production system and one for test purposes. And none of them may be part of the sysop group. How can you use different accounts?

The central settings of pywikibot are made in config.py and there may be a user-config.py which is able to override the default setting in config.py. The minimum settings of user-config.py is the default family where the bot is running and the bot account related to this family. This is made by the following entry:

mylang = 'cs'
family = 'wikipedia'
usernames['wikipedia']['cs'] = 'Test1'

where mylang and family determines the site, and usernames determines a account name for specific sites.

Pywikibot provides global options which are able to override (user-)config settings. [1] The most commen options are -lang and -family to change the default site a bot is working on. With Pywikibot release 5.2 a -site option was added to determine the site directly.

In the same way as the default site can be overridden by these options given above, there is a -user option to override the user account given with user-config.py.

Finally there is another global option -dir which can change the directory where to read the user-config.py file; this enables to have several config files to be chosen.

All global options are available with scripts shipped with Pywikibot framework. Just call:

<scriptname> <global options>

Global options can also be used with you privat scripts if the pywikibot.handle_args function [2] is used. If you don't want to use this argument parser you can use the "magic" pwb wrapper script [3]. All you have to do is to call you script via this wrapper script:

pwb <global options> <scriptname> <scipts options>

Now we have two ways using multiple accounts running a script:
# Use global -user option like <scriptname> -user:<user name>
# create a user-config.py for each account within a sub folder (or elsewhere) and use -dir option like <scriptname> -dir:<folder>

By the way you don't need to have a user-config.py file to run Pywikibot[4]. If you have installed Pywikibot s a site-package (pip install pywikibot), user-config.py is deactivated by default but there is a code entry point script pwb.exe which acts as the pwb wrapper described above and with the documentation below.

A third way is to pass the user name to the pywikibot.Site() constructor like

site = pywikibot.Site(user=<user name>) [5]

I hope this helps a bit.

Best
xqt

[1] https://doc.wikimedia.org/pywikibot/stable/global_options.html
[2] https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.html?highlight=handle_args#pywikibot.handle_args
[3] https://doc.wikimedia.org/pywikibot/stable/utilities/scripts_ref.html#module-pwb
[4] https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.config.html?highlight=pywikibot_no_user_config
[5] https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.html#pywikibot.Site

 
Von: Erik Sommer <ersotech@posteo.de>
Gesendet: 05.09.2022 16:14
An: <pywikibot@lists.wikimedia.org>
Betreff: [pywikibot] authenticate as bot and sysop
 

Hi list,

I operate currently a bot on the German Wikisource. The bot was granted both groups, admin and bot. It is intended to be used as automated protection bot. I'm having trouble to put the right credentials in my user-config.py.

It is currently coded like following pseudo-code:

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

family = 'wikisource'
mylang = 'de'
usernames['wikisource']['de'] = '******'

authenticate['de.wikisource.org'] = (....*****.....)

the problem with this is that the framework only detect my bot as bot not as sysadmin. Groups taken from the debugging output: ['bot', '*', 'user', 'autoconfirmed']

What do I have to add to my config, that the bot also get picket up as sysadmin? I already read (https://www.mediawiki.org/wiki/Manual:Pywikibot/user-config.py) but doesn't make sense for me. It will not change anything if add the botname a second time to the usernames dictionary.

Best Regards

Erik Sommer