Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_tournament_api_key(key):
"""
Set your tournament API key
Args:
key (str): the key to use
"""
cassiopeia.dto.requests.tournament_api_key = key
if not cassiopeia.dto.requests.tournament_rate_limiter:
cassiopeia.dto.requests.tournament_rate_limiter = cassiopeia.type.api.rates.MultiRateLimiter((10, 10), (500, 600))
def get_featured_games():
"""
https://developer.riotgames.com/api/methods#!/977/3337
Returns:
FeaturedGames: the current featured game list
"""
request = "https://{server}.api.pvp.net/observer-mode/rest/featured".format(server=cassiopeia.dto.requests.region)
return cassiopeia.type.dto.featuredgames.FeaturedGames(cassiopeia.dto.requests.get(request, include_base=False))
def get_champion_status(id_):
"""
https://developer.riotgames.com/api/methods#!/1015/3443
Args:
id (int): the ID of the champion to look up
Returns:
Champion: the champion
"""
request = "{version}/champion/{id_}".format(version=cassiopeia.dto.requests.api_versions["champion"], id_=id_)
return cassiopeia.type.dto.champion.Champion(cassiopeia.dto.requests.get(request))
# Convert core types to API-ready types
if isinstance(begin_time, datetime.datetime):
epoch = datetime.datetime.utcfromtimestamp(0)
delta = begin_time - epoch
begin_time = int(delta.total_seconds() * 1000)
if isinstance(end_time, datetime.datetime):
epoch = datetime.datetime.utcfromtimestamp(0)
delta = end_time - epoch
end_time = int(delta.total_seconds() * 1000)
champion_ids = [champion.id for champion in champions] if isinstance(champions, list) else champions.id if champions else None
ranked_queues = [queue.value for queue in ranked_queues] if isinstance(ranked_queues, list) else ranked_queues.value if ranked_queues else None
seasons = [season.value for season in seasons] if isinstance(seasons, list) else seasons.value if seasons else None
history = cassiopeia.dto.matchlistapi.get_match_list(summoner.id, num_matches, begin_index, begin_time, end_time, champion_ids, ranked_queues, seasons)
# Load required data if loading policy is eager
if cassiopeia.core.requests.load_policy is cassiopeia.type.core.common.LoadPolicy.eager:
cassiopeia.riotapi.get_champions() if history.champion_ids else None
return [cassiopeia.type.core.matchlist.MatchReference(ref) for ref in history.matches]
def get_champion(id_):
"""
https://developer.riotgames.com/api/methods#!/968/3322
Args:
id_ (int): the ID of the champion to get
Returns:
Champion: the champion
"""
request = "{version}/champion/{id_}".format(version=cassiopeia.dto.requests.api_versions["staticdata"], id_=id_)
params = {"champData": "all"}
if _locale:
params["locale"] = _locale
return cassiopeia.type.dto.staticdata.Champion(cassiopeia.dto.requests.get(request, params, True))
def get_top_champion_masteries(summoner, max_entries=3):
"""
Gets the top ChampionMastery objects for the specified summoner
Args:
summoner (Summoner): the summoner to get champion mastery for
max_entries (int): the maximum number of entires to retrieve (default 3)
Returns:
list: the summoner's top champion masteries
"""
champion_masteries = cassiopeia.dto.championmasteryapi.get_top_champion_masteries(summoner.id, max_entries)
# Load required data if loading policy is eager
if champion_masteries and cassiopeia.core.requests.load_policy is cassiopeia.type.core.common.LoadPolicy.eager:
cassiopeia.riotapi.get_champions()
return [cassiopeia.type.core.championmastery.ChampionMastery(cm) for cm in champion_masteries]
https://developer.riotgames.com/api/methods#!/1018/3452
Args:
summoner_id (int): the summoner to get ranked stats for
season (str): the season to get ranked stats for ("SEASON2015", "SEASON2014", "SEASON3") (default None)
Returns:
RankedStats: the ranked stats for the summoner and season specified
"""
request = "{version}/stats/by-summoner/{id_}/ranked".format(version=cassiopeia.dto.requests.api_versions["stats"], id_=summoner_id)
params = {}
if season:
params["season"] = season
return cassiopeia.type.dto.stats.RankedStats(cassiopeia.dto.requests.get(request, params))
allowed_summoners (list): the summoners who are allowed to participate in the tournament (default [])
spectator_type (str | SpectatorType): the spectator availability for the tournament (default None)
pick_type (str | PickType): the pick type for the tournament (default None)
map_type (str | MapType): the map the tournament is played on (default None)
"""
if isinstance(tournament_code, cassiopeia.type.core.tournament.TournamentCode):
tournament_code = tournament_code.code
if spectator_type and not isinstance(spectator_type, cassiopeia.type.core.tournament.SpectatorType):
spectator_type = cassiopeia.type.core.tournament.SpectatorType(spectator_type.upper())
if pick_type and not isinstance(pick_type, cassiopeia.type.core.tournament.PickType):
pick_type = cassiopeia.type.core.tournament.PickType(pick_type.upper())
if map_type and not isinstance(map_type, cassiopeia.type.core.tournament.MapType):
map_type = cassiopeia.type.core.tournament.MapType(map_type.upper())
summoners = ",".join([str(summoner.id) for summoner in allowed_summoners])
parameters = cassiopeia.type.dto.tournament.TournamentCodeUpdateParameters(summoners, spectator_type.value if spectator_type else "", pick_type.value if pick_type else "", map_type.value if map_type else "")
cassiopeia.dto.tournamentapi.update_tournament_code(tournament_code, parameters)