mwcleric package¶
Subpackages¶
Submodules¶
mwcleric.auth_credentials module¶
- class mwcleric.auth_credentials.AuthCredentials(username=None, password=None, user_file=None, start_over=False)¶
Bases:
object
Stores username and password for future use with a WikiClient. Specify either user_file or both username and password.
If using a file, files can be either located in the same directory as the code, or in the config directory of the user. If files in both locations exist, files in the former location will trump those in the latter.
- Parameters:
username – Username, this must include an @ if using a bot password
password – Password, this is the actual value of the password, not the “name” of a “bot password”
user_file – Either a file or a system variable as a nicknamed account to look for
- config_path = '/home/docs/.config/mwcleric'¶
- file_pattern = 'wiki_account_{}.json'¶
- get_user_data_from_file(user_file, base_path)¶
- password = None¶
- static prompt_user_info()¶
- static read_user_info(file)¶
- save_account_data(account_data, user_file)¶
- site_pw = None¶
- site_user = None¶
- static update_legacy_user_info(legacy_user_file, legacy_pw_file, account_file)¶
- username = None¶
mwcleric.errors module¶
- exception mwcleric.errors.InvalidNamespaceName¶
Bases:
KeyError
- exception mwcleric.errors.InvalidUserFile¶
Bases:
KeyError
- exception mwcleric.errors.PageModifierNotImplemented¶
Bases:
NotImplementedError
- exception mwcleric.errors.PatrolRevisionInvalid¶
Bases:
KeyError
- exception mwcleric.errors.PatrolRevisionNotSpecified¶
Bases:
KeyError
- exception mwcleric.errors.RetriedLoginAndStillFailed(action, codes)¶
Bases:
AssertUserFailedError
- exception mwcleric.errors.TemplateModifierNotImplemented¶
Bases:
NotImplementedError
mwcleric.fandom_client module¶
- class mwcleric.fandom_client.FandomClient(wiki: str, client: Site | None = None, credentials: AuthCredentials | None = None, lang: str | None = None, **kwargs)¶
Bases:
WikiClient
Functions for connecting to and editing specifically Fandom wikis.
Create a site object.
- Parameters:
wiki – Name of a wiki
lang – Optional. If the wiki has a language path in the URL, provide it here.
client – Optional. If this is provided, SessionManager will not be used.
credentials – Optional. Provide if you want a logged-in session.
- cargo_client: CargoClient = None¶
- login()¶
- relog()¶
Completely discards pre-existing session and creates a new site object :return:
- search(search_term: str, title_list: List[str], limit: int = 500)¶
Searches a specified list of titles for a given term. A replacement for Fandom’s lack of insource search.
This method paginates the requests to fetch page sources, so it’s relatively efficient, especially if you are logged in as an administrator with apihighlimits.
- Parameters:
search_term – The term to search
title_list – A list of page titles.
limit – The pagination limit when querying for page texts. If you are logged out or not a systop, probably 50.
- Returns:
Nothing, will print a list of the results
- search_namespace(search_term: str, namespace: int | str, limit: int = 500)¶
Searches a specified namespace for a search term.
If you want to search the entire wiki, use search instead.
- Parameters:
search_term – The term to search
namespace – The namespace within which to search for the term.
limit – The pagination limit when querying for page texts. If you are logged out or not a systop, probably 50.
- Returns:
Nothing, will print a list of the results
- wiki: str = None¶
mwcleric.page_modifier module¶
- class mwcleric.page_modifier.PageModifierBase(site: WikiClient, page_list=None, title_list=None, limit=-1, summary=None, startat_page=None, tags=None, skip_pages=None, quiet=False, lag=0, **data)¶
Bases:
object
Update pages on a wiki by using update_wikitext or update_plaintext.
Available attributes you can change:
self.current_text (do this in self.update_plaintext()
self.current_wikitext (do this in self.update_wikitext()
Available attributes you can use but not modify:
self.current_page, which is an mwclient Page, so you can access page.name, etc
self.site, a WikiClient object
Specify a summary on initialization along with either a page_list or a title_list.
page_list is a list of Page objects (for example maybe site.client.categories)
title_list is a list of strings which will be turned into Page objects
Create a PageModifier object, which can perform operations to edit the plaintext or wikitext of a page.
- Parameters:
site – a WikiClient to perform the edits on
page_list – a list of Page objects to operate on, do not use with title_list
title_list – a list of title strings to operate on, do not use with page_list
limit – stop after scanning this many pages
summary – edit summary
startat_page – skip to this page
quiet – don’t print any console output (set to True for cron processes)
lag – sleep this many seconds before saving
data – Extra keywords to save to the class for use in the update_wikitext/update_plaintext methods
- current_page = None¶
- current_text = None¶
- current_wikitext = None¶
- postprocess_plaintext(text)¶
This method may not be supported forever, do not use it!!!
It’s only here because TemplateModifier requires it due to mwparserfromhell’s node removal not completely removing newlines when removing nodes.
- prioritize_plaintext = False¶
- prioritize_wikitext = False¶
- run()¶
- update_plaintext(text)¶
This will be run iff update_plaintext isn’t overridden in a subclass.
Modify text and return it.
- update_wikitext(wikitext)¶
This will be run iff update_wikitext isn’t overridden in a subclass.
Modify wikitext in place.
mwcleric.template_modifier module¶
- class mwcleric.template_modifier.TemplateModifierBase(site: WikiClient, template, page_list=None, title_list=None, limit=-1, summary=None, quiet=False, lag=0, tags=None, skip_pages=None, recursive=True, startat_page=None, namespace: int | str | None = None, **data)¶
Bases:
PageModifierBase
- Parameters:
site – WikiClient site
template – The template to modify
page_list – A default page_list parameter. Otherwise the template’s used_in list will be used
title_list – See page_list.
limit – See PageModifier class.
summary – See PageModifier class.
quiet – See PageModifier class.
lag – See PageModifier class.
tags – See PageModifier class.
skip_pages – See PageModifier class.
recursive – See mwparserfromhell.wikitext.filter_templates method
startat_page – See PageModifier class
namespace – Do we filter the template’s used_in list?
data – Extra keywords to save to the class for use in the update_template method
- postprocess_plaintext(text)¶
This method may not be supported forever, do not use it!!!
It’s only here because TemplateModifier requires it due to mwparserfromhell’s node removal not completely removing newlines when removing nodes.
- remove_from_page()¶
Marks the template to remove it completely from the page in a later layer of processing
- update_template(template)¶
- update_wikitext(wikitext)¶
This will be run iff update_wikitext isn’t overridden in a subclass.
Modify wikitext in place.
mwcleric.wiki_client module¶
- class mwcleric.wiki_client.WikiClient(url: str, path='/', credentials: AuthCredentials | None = None, client: Site | None = None, max_retries=3, retry_interval=10, max_retries_mwc: int = 0, cargo: bool = False, **kwargs)¶
Bases:
object
Various utilities that extend mwclient and could be useful on any wiki/wiki farm Utilities here should not depend on any extensions There’s no intention to develop anything that’s not useful on Gamepedia/Gamepedia esports wikis but anything that’s platform or extension-specific will go in GamepediaSite instead
- append(page: Page, append_text, summary='', minor=False, bot=True, section=None, **kwargs)¶
- append_title(title: str, append_text, summary='', minor=False, bot=True, section=None, **kwargs)¶
- client = None¶
- delete(page: Page, reason='', watch=False, unwatch=False, oldimage=False)¶
- get_ns_number(ns: str)¶
- get_simple_pages(title_list: List[str], limit: int) List[SimplePage] ¶
- last_edited_interval(page: Page | str) timedelta ¶
- login()¶
- logs_by_interval(minutes, offset=0, lelimit='max', leprop='details|type|title|tags', **kwargs)¶
- move(page: Page, new_title, reason='', move_talk=True, no_redirect=False, move_subpages=False, ignore_warnings=False)¶
- property namespaces¶
- pages_using(template: str | List[str], namespace: int | str | None = None, filterredir='all', limit=None, generator=True, unique=True) List[Page] | Generator[Page, None, None] ¶
Returns the list of pages using the provided template or templates
- Parameters:
template – A template or list of templates to operate on
namespace – Optional - the namespace to restrict the result set to
filterredir – Passed directly to the MediaWiki api - filter redirects in the result?
limit – Passed directly to the MediaWiki api - limit the number of results?
generator – Default True - return result as a generator? If False, result will be a list
unique – Default True, but only has an effect if generator is False. Remove duplicates from the list output?
- Returns:
A list or generator of Page objects containing all the results of what transcludes the input(s)
- patrol(revid=None, rcid=None, **kwargs)¶
- prepend(page: Page, prepend_text, summary='', minor=False, bot=True, section=None, **kwargs)¶
- prepend_title(title: str, prepend_text, summary='', minor=False, bot=True, section=None, **kwargs)¶
- purge(page: Page)¶
- purge_title(title: str)¶
- recent_pages_by_interval(*args, **kwargs)¶
- recent_titles_by_interval(*args, **kwargs)¶
- recentchanges_by_interval(minutes, offset=0, prop='title|ids|tags|user|patrolled', **kwargs)¶
- relog()¶
Completely discards pre-existing session and creates a new site object :return:
- save(page: Page, text, summary='', minor=False, bot=True, section=None, **kwargs)¶
Performs a page edit, retrying the login once if the edit fails due to the user being logged out
This function hopefully makes it easy to workaround the lag and frequent login timeouts experienced on the Fandom UCP platform compared to Gamepedia Hydra.
- Parameters:
page – mwclient Page object
text – as in mwclient.Page.edit
summary – as in mwclient.Page.edit
minor – as in mwclient.Page.edit
bot – as in mwclient.Page.edit
section – as in mwclient.Page.edit
kwargs – as in mwclient.Page.edit
- Returns:
nothing
- save_tile(title: str, text, summary=None, minor=False, bot=True, section=None, **kwargs)¶
- save_title(title: str, text, summary=None, minor=False, bot=True, section=None, **kwargs)¶
- target(name: str) str | None ¶
Return the name of a page’s redirect target
- Parameters:
name – Name of page
- Returns:
Name of page’s redirect target
- touch(page: Page)¶
- touch_title(title: str)¶
- upload(file: str | None = None, filename: str | None = None, description: str | None = None, ignore_warnings: bool = False, url: str | None = None, filekey: str | None = None, comment: str | None = None, **kwargs)¶
Uploads a file from a local directory or a URL. Only one of file, filekey or url must be specified. Retries in case the upload fails.
- Parameters:
file – File object to upload
filename – Destination filename without including a prefix like File:
description – Wikitext description for the file
ignore_warnings – Whether to ignore warnings raised by the API
url – URL to fetch the file from, disabled in some wikis
filekey – Key that identifies a previous upload that was stashed temporarily
comment – Comment for the upload, will be used as the initial page text for new files if description is not provided.
kwargs – Extra arguments to be passed to mwclient
- url = None¶
- write_errors = (<class 'mwclient.errors.AssertUserFailedError'>, <class 'requests.exceptions.ReadTimeout'>, <class 'mwclient.errors.APIError'>, <class 'mwclient.errors.MaximumRetriesExceeded'>)¶