Package: river-mwclient
River's tools for writing Python scripts for Leaguepedia / other Gamepedia esports wikis.This library is basically anmwclient(https://github.com/mwclient/mwclient) wrapper, it has some built-in error handling for you, some Cargo support, and most importantly decreases the number of lines of code needed to create and log into a site object from like 3 to 1. It's intended for my wikis primarily but feel free to clone/use.Install/upgrade:This library can be installed from PyPI:pip install river-mwclientHowever, for the most up-to-date version including minor changes for Leaguepedia-specific needs you may want to pull directly from the repo if I haven't updated on PyPI:pip install -U git+git://github.com/RheingoldRiver/river_mwclientIf you're using PyCharm, press alt+F12 to open the console and you can install directly to your venv or whatever it's using that way.Logging inThe functionloginshould be your single point of entry to create anEsportsSiteobject. This function expects the following files inthe same directory as your code:username_me.txt- your user name (for the loginme) for example,RheingoldRiver@Pythonpassword_me.txt- your bot password (for the loginme) this will be a long string of characters from Special:BotPasswordsusername_bot.txt- your bot's user name (for the loginbot) for example,RiverIsABot@Pythonpassword_bot.txt- your bot's bot password (for the loginbot)Note - you may not have two accounts! That's okay; in this case, just makeusername_meandpassword_me, and don't create thebotcredential set.These files would allow you to log in asmeor asbot. Remember the username includes both your account nameand also the name of your bot password, separated by an@.If you prefer, you can set environment variables calledWIKI_USERNAME_ME,WIKI_PASSWORD_ME, etc.If you don't want to log in, you can just create an EsportsSite/GamepediaSite object and never log in.Bot password best practicesUse a unique password just for your Python code that isn't also used for any other serviceIn fact you should do this for every separate application that you use a bot password inEditingFor people wanting to edit wikis,PageModifierandTemplateModifierare the two things most likely to make your life easier. To use them you subclass and then overwrite methods to modify the page or template as needed, then instantiate the subclass and run.ForPageModifier, you probably wanteitherupdage_plaintextorupdate_wikitext, not both.Copyable codefromriver_mwclient.esports_clientimportEsportsClientfromriver_mwclient.auth_credentialsimportAuthCredentialsfromriver_mwclient.template_modifierimportTemplateModifierBasecredentials=AuthCredentials(user_file="me")site=EsportsClient('lol',credentials=credentials)summary='Bot edit'classTemplateModifier(TemplateModifierBase):defupdate_template(self,template):returnTemplateModifier(site,'TEMPLATEYOUCAREABOUT',summary=summary).run()fromriver_mwclient.esports_clientimportEsportsClientfromriver_mwclient.auth_credentialsimportAuthCredentialsfromriver_mwclient.page_modifierimportPageModifierBasecredentials=AuthCredentials(user_file="me")site=EsportsClient('lol',credentials=credentials)summary='Bot edit'classPageModifier(PageModifierBase):defupdate_plaintext(self,text):returntextdefupdate_wikitext(self,wikitext):returnPageModifier(site,summary=summary).run()ContributingIf you want to contribute feel free to open a pull request, as long as whatever you add works, the only way I wouldn't accept is if it actively interferes with my existing code (but that does include being poorly organized etc so pls actually make it a nice change).