My bot needs to be able to run as either of two different accounts depending on the task. DYKToolsBot for most things, DYKToolsAdminBot for specific tasks that need admin rights. How do I do this?
I'm not using the pwb.py driver layer; I've got my own top-level driver code and just import pywikibot as a library.
I thinking maybe I want to use PYWIKIBOT_NO_USER_CONFIG=2 and ignore the user-config.py stuff completely, but it's not clear how I pass the config into the library. Family and mylang are easy; I just pass those directly to pywikibot.Site(). But It's not clear what to do with username and the OAuth credentials that are currently in authenticate[]. Do I just create a login.OauthLoginManager and call login() on that?
Roy Smith roy@panix.com ezt írta (időpont: 2023. febr. 24., P, 0:42):
My bot needs to be able to run as either of two different accounts depending on the task. DYKToolsBot for most things, DYKToolsAdminBot for specific tasks that need admin rights. How do I do this?
I just got up to quickly wirite somewhere that we need separate user-fixes.pys per user, best defined in config.py, and this mail waited me here. :-) So we should have per user configs.
An ugly workaround by that time what I did with logins: a Windows batch. ren other.lwp temp.lwp ren pywikibot.lwp other.lwp ren temp.lwp pywikibot.lwp
If you start your scripts froma batch (or Linux script), this is no extra pain with user-config.py.
Creating a OauthLoginManager directly isn't working.
site = Site('wikipedia:test', user='RoySmith') manager = OauthLoginManager(consumer_secret, site, consumer_token)
with PYWIKIBOT_NO_USER_CONFIG=1
gets me
user-config.py cannot be loaded. family and mylang are not set. Defaulting to family='wikipedia' and mylang='test'. Traceback (most recent call last): File "/Users/roy/dev/dyk-tools/venv/lib/python3.9/site-packages/pywikibot/login.py", line 99, in __init__ user = code_to_usr.get(site.code) or code_to_usr['*'] KeyError: '*'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/roy/temp/bot.py", line 13, in <module> manager = OauthLoginManager(consumer_secret, site, consumer_token) File "/Users/roy/dev/dyk-tools/venv/lib/python3.9/site-packages/pywikibot/login.py", line 373, in __init__ super().__init__(password=None, site=site, user=None) File "/Users/roy/dev/dyk-tools/venv/lib/python3.9/site-packages/pywikibot/login.py", line 101, in __init__ raise NoUsernameError( pywikibot.exceptions.NoUsernameError: ERROR: username for wikipedia:test is undefined. If you have a username for that site, please add a line to user config file (user_config.py) as follows: usernames['wikipedia']['test'] = 'myUsername' CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.NoUsernameError'>
On Feb 23, 2023, at 6:42 PM, Roy Smith roy@panix.com wrote:
I thinking maybe I want to use PYWIKIBOT_NO_USER_CONFIG=2 and ignore the user-config.py stuff completely, but it's not clear how I pass the config into the library. Family and mylang are easy; I just pass those directly to pywikibot.Site(). But It's not clear what to do with username and the OAuth credentials that are currently in authenticate[]. Do I just create a login.OauthLoginManager and call login() on that?