mwrogue package

Subpackages

Submodules

mwrogue.auth_credentials module

class mwrogue.auth_credentials.AuthCredentials(username=None, password=None, user_file=None, start_over=False)

Bases: AuthCredentials

Wrapper class just to make imports nicer to work with

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

mwrogue.errors module

exception mwrogue.errors.CantFindMatchHistory

Bases: KeyError

exception mwrogue.errors.EsportsCacheKeyError(file, value, length, value_table)

Bases: KeyError

exception mwrogue.errors.InvalidEventError

Bases: KeyError

mwrogue.esports_client module

class mwrogue.esports_client.EsportsClient(wiki: str, client: Optional[Site] = None, credentials: Optional[AuthCredentials] = None, cache: Optional[EsportsLookupCache] = None, lang: Optional[str] = None, **kwargs)

Bases: FandomClient

Functions for connecting to and editing specifically to Gamepedia esports wikis.

If not using an esports wiki, please use GamepediaSite instead.

Create a site object.

Parameters
  • wiki – Name of a wiki

  • client – WikiClient object. If this is provided, SessionManager will not be used.

  • credentials – Optional. Provide if you want a logged-in session.

  • stg – if it’s a staging wiki or not

ALL_ESPORTS_WIKIS = ['lol', 'halo', 'smite', 'vg', 'rl', 'pubg', 'fortnite', 'apexlegends', 'fifa', 'gears', 'nba2k', 'paladins', 'siege', 'splatoon2', 'legendsofruneterra', 'default-loadout', 'commons', 'teamfighttactics', 'valorant']
backup_template(template: Template, page: Union[str, Page], key: Union[str, List[str]])

Backs up a template in the Backup namespace. The template can later be restored with get_restored_template.

Parameters
  • template – Template object

  • page – Page or title where the template is located on

  • key – Identifying set of params that we can use to locate the template when we restore it

Returns

null

cargo_client: CargoClient = None
client: Site = None
create_tables(tables)
data_pages(event)

Find all the data pages for an event.

Parameters

event – Overview Page of event

Returns

generator of data pages

get_data_and_timeline(rpgid: str, version: Literal[4, 5] = 4)

Queries Leaguepedia to return two jsons: The data & timeline from a single game.

This function is limited in scope: It will not allow you to query multiple games in a single query; however, the MediaWiki API does support this. It also will not allow you to drop one of the jsons for a smaller response package if you don’t require all of the data. You also must know the ID in advance. You can find IDs by querying the MatchScheduleGame Cargo table and looking up the RiotPlatformGameId field.

Raises a KeyError in the case that data is not found. If Timeline is not found, None will be returned for that json (this happens for chronobreaks).

This function is unavailable on wikis other than Leaguepedia.

Parameters
  • rpgid – A single riot_platform_game_id

  • version – The API version of the json to download. Defaults to 4.

Returns

Two jsons, the data & timeline for the game

get_data_and_timeline_from_gameid(game_id: str)

Queries Leaguepedia to return two jsons: The data & timeline from a single game.

Parameters

game_id – The Leaguepedia game_id

Returns

Two jsons, the data & timeline for the game

get_one_data_page(event, i)

Find one data page for an event

Parameters
  • event – Overview Page of an event

  • i – the ith page to return

Returns

a Page object of a single data page

get_restored_template(template: Template, page: Union[str, Page], key: Union[str, List[str]]) Optional[Template]

Looks for the backed-up version of the specified template on the backup page & returns it

The template should have been backed up using the backup_template method earlier.

Parameters
  • template – Template object that we want to restore from backup page

  • page – Page or title where the template is located on

  • key – Identifying set of params to use to restore the template from

Returns

Template object, if found, else None

static get_wiki(wiki)
log_error_content(title: Optional[str] = None, text: Optional[str] = None)
log_error_script(title: Optional[str] = None, error: Optional[Exception] = None)
query_bayes_id(idx)
query_qq_mh(qq_id)
query_riot_mh(riot_mh)
query_wp_mh(wp_id)
recreate_tables(tables, replacement=True)
report_all_errors(error_title)
setup_tables(tables)
tournaments_to_skip(script)
tournaments_to_skip_where(script, field)
wiki: str = None

mwrogue.lookup_cache module

class mwrogue.lookup_cache.EsportsLookupCache(site: Site, cargo_client: Optional[CargoClient] = None)

Bases: object

clear()
get(filename, key, length, allow_fallback=False)

Returrns the length of the lookup of a key requested from the filename requested. Assumes the file has the same structure as the -names modules on Leaguepedia.

Parameters
  • filename – “Champion”, “Role”, etc. - the name of the file

  • key – The lookup key, e.g. “Morde”

  • length – The length of value to return, e.g. “long” or “link”

  • allow_fallback – Whether or not to fallback to returning the key if it’s missing in the lookup

Returns

Correct lookup value provided, or None if it’s not found

Returns

Correct lookup value provided, or None if it’s not found

get_disambiguated_player_from_event(event, team, player)

Returns the disambiguated ID of the player based on the team they were playing on in the event.

For performance, the first time a team & event are queried, a single network call will be made to retrieve all possible player names for that event.

These will be stored in a three-layer dictionary keyed first by event, then by team, then finally by player ID (not disambiguated), and ultimately yielding disambiguated player ID Because it’s possible for a player to rename mid-event, we will just include every lifetime ID the player has ever had, so that future requests in the same session can use other IDs. The current request will use the ID requested by the current function call.

This method has a failure chance if two players on the same team historically shared an ID We could attempt to mitigate this failure chance by checking position

TODO: Add support for low-priority disambiguation table, this will also mitigate this possibility

teams are themselves listed within tournaments

Parameters
  • event – will be resolved as a redirect if needed

  • team – can be a tricode if needed

  • player – the current player ID to return the disambiguated name of

Returns

the disambiguated form of the player param

get_target(title)

Caches & returns the target of a title of a wiki page, caching the result and returning the cached result if possible

Parameters

title – Title of a page on the wiki

Returns

Redirect target of the title

get_team_from_event_tricode(event, tricode)

Determines the full name of a team based on its tricode, assuming tricode matches the short name on the wiki and that tricodes are unique within the provided event

Parameters
  • event – Event within which to restrict the lookup

  • tricode – Official tricode of the team, must match wiki teamshort

Returns

Wiki teamlinkname

static unescape(string)

mwrogue.template_modifier module

class mwrogue.template_modifier.TemplateModifierBase(site: EsportsClient, 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: Optional[Union[int, str]] = None, **data)

Bases: TemplateModifierBase

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

backup(key)
restore(key)

mwrogue.wiki_time module

class mwrogue.wiki_time.WikiTime(timestamp: ~datetime.datetime, tz: ~pytz.timezone = <UTC>)

Bases: object

Leaguepedia and the other esports wikis use an EXTREMELY simplified time zone model. In this model, there are only three time zones: PST, CET, and KST. Additionally, the wiki itself does not know anything about daylight savings; instead, it relies on the user supplying DST metadata along with every timestamp. DST metadata can be supplied with three options: Yes, Spring [or Fall], or No. Yes means that both CET and PST have DST; No means that neither does, and Spring/Fall mean that PST does but CET does not. (KST, sanely, never has DST.) For simplicity, even in the fall, we return Spring.

This class reduces timestamps to this simple model and provides information in the format expected by the esports wikis.

Creates a wiki date-time object

Parameters
  • timestamp – a datetime object

  • tz – optional, a timezone. if not provided, utc will be assumed.

cet = <DstTzInfo 'Europe/Berlin' LMT+0:53:00 STD>
kst = <DstTzInfo 'Asia/Seoul' LMT+8:28:00 STD>
pst = <DstTzInfo 'America/Los_Angeles' LMT-1 day, 16:07:00 STD>

mwrogue.wiki_time_parser module

mwrogue.wiki_time_parser.time_from_str(timestamp: str, tz: Optional[timezone] = None)
mwrogue.wiki_time_parser.time_from_template(template: Template)

Pulls date-time information encoded by a template and returns a WikiTime object. If date-time information is missing or incomplete, None is returned instead.

Parameters

template – A mwparserfromhell Template object with date, time, and timezone parameters

Returns

a WikiTime object representing the date-time information encoded by this template

Module contents