River's mwclient wrapper
Project description
River's tools for writing Python scripts for Leaguepedia / other Gamepedia esports wikis.
This library is basically an mwclient
(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-mwclient
However, 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_mwclient
If 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 in
The function login
should be your single point of entry to create an EsportsSite
object. This function expects the following files in the same directory as your code:
username_me.txt
- your user name (for the loginme
) for example,RheingoldRiver@Python
password_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@Python
password_bot.txt
- your bot's bot password (for the loginbot
)
Note - you may not have two accounts! That's okay; in this case, just make
username_me
andpassword_me
, and don't create thebot
credential set.
These files would allow you to log in as me
or as bot
. Remember the username includes both your account name and also the name of your bot password, separated by an @
.
If you prefer, you can set environment variables called WIKI_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 practices
- Use a unique password just for your Python code that isn't also used for any other service
- In fact you should do this for every separate application that you use a bot password in
Editing
For people wanting to edit wikis, PageModifier
and TemplateModifier
are 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.
For PageModifier
, you probably want either updage_plaintext
or update_wikitext
, not both.
Copyable code
from river_mwclient.esports_client import EsportsClient
from river_mwclient.auth_credentials import AuthCredentials
from river_mwclient.template_modifier import TemplateModifierBase
credentials = AuthCredentials(user_file="me")
site = EsportsClient('lol', credentials=credentials)
summary = 'Bot edit'
class TemplateModifier(TemplateModifierBase):
def update_template(self, template):
return
TemplateModifier(site, 'TEMPLATEYOUCAREABOUT',
summary=summary).run()
from river_mwclient.esports_client import EsportsClient
from river_mwclient.auth_credentials import AuthCredentials
from river_mwclient.page_modifier import PageModifierBase
credentials = AuthCredentials(user_file="me")
site = EsportsClient('lol', credentials=credentials)
summary = 'Bot edit'
class PageModifier(PageModifierBase):
def update_plaintext(self, text):
return text
def update_wikitext(self, wikitext):
return
PageModifier(site,
summary=summary).run()
Contributing
If 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).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file river_mwclient-0.5.0.tar.gz
.
File metadata
- Download URL: river_mwclient-0.5.0.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6aec544389af478f6c973ad30450f298ac73e3114c88c5e634f84bf4907c519 |
|
MD5 | e796a0c96daa479963f21f154d9ae1e0 |
|
BLAKE2b-256 | 9f4f6a59dabf74e2b935b9e1361c7a2f817424b8f706fc40ca105ae26716e459 |