I'm not using the bot.py driver, just calling pywikibot.Site() directly. How do I make it read an alternate config file in that situation?
On Feb 26, 2023, at 4:48 AM, info@gno.de wrote:
Hi,
renaming the password cookie file is not a good idea after Pywikibot 8.0.0 was released because each account has its own file. [1]
You may have different user config files which can be used with global -config option e.g. -config:mybot_config. [2] This new global option was introduced with Pywikibot 7.7 [3]
Best xqt
[1] https://phabricator.wikimedia.org/rPWBCba56084e12a496bbb4f71dfea0fd88a818c18... [2] https://doc.wikimedia.org/pywikibot/master/global_options.html#global-option... [3] https://phabricator.wikimedia.org/rPWBCa02dc8dcf93ebb35e0b24884eddc6a4ff5175...
Von: Bináris wikiposta@gmail.com Gesendet: 24.02.2023 04:27 An: Pywikibot discussion list pywikibot@lists.wikimedia.org Betreff: [pywikibot] Re: Multiple users in user-config.py?
Roy Smith <roy@panix.com mailto: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.
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
Hmmm.
I was reading through that code earlier today, and I assumed I was just in the wrong place. I got as far as:
exec(compile(f.read(), _filename, 'exec'), _exec_globals)
and paused. I had been wondering about how user-config.py was getting imported, since that's not a valid module name. Now I know. It's not imported. It's executed. That's, um, unexpected :-)
Please forgive me if I sound a bit negative here. This is my first pywikibot project. I've used mwclient quite a bit in the past, but it's really too low level, exposing too many details of the MediaWiki API. It's also close to being abandonware, so for this project I decided it was time to give pywikibot a try.
What I'm finding with pywikibot is that the low-level stuff (Site, Page, etc) is mostly well designed and easy to work with. The level of abstraction it presents seems just about right. Exposing datetimes instead of raw mw timestamps is a win. Another win is pwb's "total" parameter to limit query results, compared to mwclient's unintuitive "limit", which is almost certainly not what you want. Those two things were what drove me to write my own mwclient wrapper library a couple of years ago. Eventually I realized I was reinventing much of pywikibot, which was silly.
However, what I keep bumping up against is that there's excessively tight coupling between the library layer https://doc.wikimedia.org/pywikibot/stable/library_usage.html and the command-line scripting layer. I described one example of this in T326650 https://phabricator.wikimedia.org/T326650. This seems like a similar case. An API library really shouldn't know anything about command line flags. Or config files.
A good model is the python library's logging module. It provides the ability to read its config from a file, but there's a clean separation between that and the rest of the module. If you don't want to use the config file, you can skip it entirely and build your config via whatever method is convenient to your application. This really should work the same way.
On Feb 26, 2023, at 10:14 AM, info@gno.de wrote:
Hi Roy,
this is a global option which is handled by config.py directly by reading from sys.argv but does not remove it from that list.
To remove it you can use the pwb.py wrapper like pwb <global options> <script name> <script options>. Otherwise you have to handle this vector by your script, maybe you can just ignore that option by your script.
Best xqt
Am 26.02.2023 um 15:28 schrieb Roy Smith roy@panix.com:
I'm not using the bot.py driver, just calling pywikibot.Site() directly. How do I make it read an alternate config file in that situation?
On Feb 26, 2023, at 4:48 AM, info@gno.de mailto:info@gno.de wrote:
Hi,
renaming the password cookie file is not a good idea after Pywikibot 8.0.0 was released because each account has its own file. [1]
You may have different user config files which can be used with global -config option e.g. -config:mybot_config. [2] This new global option was introduced with Pywikibot 7.7 [3]
Best xqt
[1] https://phabricator.wikimedia.org/rPWBCba56084e12a496bbb4f71dfea0fd88a818c18... https://phabricator.wikimedia.org/rPWBCba56084e12a496bbb4f71dfea0fd88a818c18a81 [2] https://doc.wikimedia.org/pywikibot/master/global_options.html#global-option... https://doc.wikimedia.org/pywikibot/master/global_options.html#global-options [3] https://phabricator.wikimedia.org/rPWBCa02dc8dcf93ebb35e0b24884eddc6a4ff5175... https://phabricator.wikimedia.org/rPWBCa02dc8dcf93ebb35e0b24884eddc6a4ff517584a
Von: Bináris <wikiposta@gmail.com mailto:wikiposta@gmail.com> Gesendet: 24.02.2023 04:27 An: Pywikibot discussion list <pywikibot@lists.wikimedia.org mailto:pywikibot@lists.wikimedia.org> Betreff: [pywikibot] Re: Multiple users in user-config.py?
Roy Smith <roy@panix.com mailto: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.
pywikibot mailing list -- pywikibot@lists.wikimedia.org mailto:pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/QRXUOHVWW2B7L3AIPUCFCZKAYUQHKEPZ/ To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org mailto:pywikibot-leave@lists.wikimedia.org
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org