Skip to main content

River's mwclient wrapper

Project description

MediaWiki Client Library for Editing and Revision In Code (MW CLERIC)

River's tools for writing Python scripts for Leaguepedia / other Gamepedia esports wikis.

This library was originally known as river_mwclient, however I renamed it because it has grown beyond the scope of just being tools for myself into a full-fledged library with a lot of utilities that's useful for many people. Thanks to pcj for coming up with the excellent name.

Install/upgrade:

This library can be installed from PyPI:

pip install mwcleric

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/mwcleric

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 expects the following files in the same directory as your code:

  • username_me.txt - your user name (for the login me) for example, RheingoldRiver@Python
  • password_me.txt - your bot password (for the login me) this will be a long string of characters from Special:BotPasswords
  • username_bot.txt - your bot's user name (for the login bot) for example, RiverIsABot@Python
  • password_bot.txt - your bot's bot password (for the login bot)

Note - you may not have two accounts! That's okay; in this case, just make username_me and password_me, and don't create the bot 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 a WikiClient 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 mwcleric.fandom_client import FandomClient
from mwcleric.auth_credentials import AuthCredentials
from mwcleric.template_modifier import TemplateModifierBase

credentials = AuthCredentials(user_file="me")
site = FandomClient("lol", credentials=credentials)
summary = 'Bot edit'


class TemplateModifier(TemplateModifierBase):
	def update_template(self, template):
		return


TemplateModifier(site, 'TEMPLATEYOUCAREABOUT',
				 summary=summary).run()
from mwcleric.fandom_client import FandomClient
from mwcleric.auth_credentials import AuthCredentials
from mwcleric.page_modifier import PageModifierBase

credentials = AuthCredentials(user_file="me")
site = FandomClient('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

mwcleric-0.4.1.tar.gz (12.7 kB view details)

Uploaded Source

File details

Details for the file mwcleric-0.4.1.tar.gz.

File metadata

  • Download URL: mwcleric-0.4.1.tar.gz
  • Upload date:
  • Size: 12.7 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

Hashes for mwcleric-0.4.1.tar.gz
Algorithm Hash digest
SHA256 1ca166802589f1847f65211469d3677ad4445f5586f8b0fea4016883d6b7c0ba
MD5 cb57e36e7cdd83b3dfbb3100fab6f56a
BLAKE2b-256 7436f7cb098a320f1597f2b5d35571ff83d9f516985147be2e046fa2d2016b58

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page