[pywikibot] Re: Multiple users in user-config.py?

2023-02-26 Thread Roy Smith
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 
 and the 
command-line scripting layer.  I described one example of this in 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, i...@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  

[pywikibot] Re: Multiple users in user-config.py?

2023-02-26 Thread info
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  

[pywikibot] Re: Multiple users in user-config.py?

2023-02-26 Thread Roy Smith
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, i...@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/rPWBCba56084e12a496bbb4f71dfea0fd88a818c18a81
> [2] 
> https://doc.wikimedia.org/pywikibot/master/global_options.html#global-options​​​
> [3] 
> https://phabricator.wikimedia.org/rPWBCa02dc8dcf93ebb35e0b24884eddc6a4ff517584a
>  
> Von: Bináris 
> Gesendet: 24.02.2023 04:27
> An: Pywikibot discussion list 
> Betreff: [pywikibot] Re: Multiple users in user-config.py?
>  
>  
>  
> Roy Smith mailto:r...@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/message/QRXUOHVWW2B7L3AIPUCFCZKAYUQHKEPZ/
> To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org

___
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/76VHT2NMNJJ6YVCDO6LDKQ2LJTXYRDTY/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org


[pywikibot] Re: Multiple users in user-config.py?

2023-02-26 Thread info
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]Bestxqt[1] https://phabricator.wikimedia.org/rPWBCba56084e12a496bbb4f71dfea0fd88a818c18a81[2] https://doc.wikimedia.org/pywikibot/master/global_options.html#global-options​​​[3] https://phabricator.wikimedia.org/rPWBCa02dc8dcf93ebb35e0b24884eddc6a4ff517584a Von: Bináris Gesendet: 24.02.2023 04:27An: Pywikibot discussion list Betreff: [pywikibot] Re: Multiple users in user-config.py?   Roy Smith <r...@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.lwpren pywikibot.lwp other.lwpren 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/message/QRXUOHVWW2B7L3AIPUCFCZKAYUQHKEPZ/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org


[pywikibot] Re: Multiple users in user-config.py?

2023-02-24 Thread Roy Smith
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 
> 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  'pywikibot.exceptions.NoUsernameError'>



> On Feb 23, 2023, at 6:42 PM, Roy Smith  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?

___
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/BK76RZNOD7AAPDIGMSYSJZMJNL57SDRI/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org


[pywikibot] Re: Multiple users in user-config.py?

2023-02-23 Thread Bináris
Roy Smith  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/message/34WRSZ4QTOB4ORFPNHINUJHJQQ5DQOKI/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org