PykeBot2.backend.stalker package

Submodules

PykeBot2.backend.stalker.battlefy module

Uses undocumented Battlefy API to scrape tournament participants.

author

Jonathan Decker

async PykeBot2.backend.stalker.battlefy.stalk_battlefy_tournament(battlefy_url: str)

Uses undocumented Battlefy API to scrape tournament participants. :param battlefy_url: A valid url to a battlefy tournament. :type battlefy_url: str :return: a TeamList object containing all Teams and Players of the given tournament. :rtype: TeamList

PykeBot2.backend.stalker.op_gg_rank module

Uses op.gg for player rank stalking and offers further functions for adding ranks to teams and calculating average rankings.

author

Jonathan Decker

async PykeBot2.backend.stalker.op_gg_rank.add_player_rank(player: PykeBot2.models.data_models.Player, session: Optional[aiohttp.client.ClientSession] = None)
Description

Calls stalk player op gg using the summoner name of the given Player and adds a Rank obj to the Player.

Parameters
  • player (Player) – A Player obj with a summoner name.

  • session (aiohttp.ClientSession) – When a session already exits, it should be reused as much as possible for better performance.

Returns

None

Return type

None

async PykeBot2.backend.stalker.op_gg_rank.add_team_list_list_ranks(team_list_list: PykeBot2.models.data_models.TeamListList, session: Optional[aiohttp.client.ClientSession] = None)
Description

Calls add team list ranks for each team list in the given team list list obj.

Parameters
  • team_list_list (TeamListList) – A team list list with a list of team lists.

  • session (aiohttp.ClientSession) – When a session already exits, it should be reused as much as possible for better performance.

Returns

None

Return type

None

async PykeBot2.backend.stalker.op_gg_rank.add_team_list_ranks(team_list: PykeBot2.models.data_models.TeamList, session: Optional[aiohttp.client.ClientSession] = None)
Description

Calls add team ranks for each team in the given team list obj.

Parameters
  • team_list (TeamList) – A team list with a list of teams.

  • session (aiohttp.ClientSession) – When a session already exits, it should be reused as much as possible for better performance.

Returns

None

Return type

None

async PykeBot2.backend.stalker.op_gg_rank.add_team_ranks(team: PykeBot2.models.data_models.Team, session: Optional[aiohttp.client.ClientSession] = None)
Description

Calls add player rank for each player of the given team. Also sets the average and max team rank.

Parameters
  • team (Team) – A team with a list of players.

  • session (aiohttp.ClientSession) – When a session already exits, it should be reused as much as possible for better performance.

Returns

None

Return type

None

PykeBot2.backend.stalker.op_gg_rank.calc_average_and_max_team_rank(team: PykeBot2.models.data_models.Team)
Description

Calculates the average and maximum rank of a given team.

If a player is unranked or the rank is unknown, then the player is ignored for the average. :param team: A team obj with players who have Rank objs. :type team: Team :return: None :rtype: None

async PykeBot2.backend.stalker.op_gg_rank.stalk_player_op_gg(sum_name: str, session: Optional[aiohttp.client.ClientSession] = None)
Description

Uses aiohttp to find the rank of a single player from op.gg.

Parameters
  • sum_name (str) – Summoner name can be taken from Player object inside Team objects.

  • session (aiohttp.ClientSession) – When a session already exits, it should be reused as much as possible for better performance.

Returns

A string representation of the Rank, should be used to create a Rank obj.

Return type

str

PykeBot2.backend.stalker.prime_league module

Handles scraping of the prime league page. :author: Jonathan Decker

Helper function to filter out non group links. :param link: Str, a web link :return: Bool, true if the link contains a keyword and leads to a group, false if not

Helper function to filter out non team links. :param link: Str, a web link :return: Bool, true if the link contains a teams, false if not

async PykeBot2.backend.stalker.prime_league.stalk_prime_league_group(prime_league_group_link: str, session: Optional[aiohttp.client.ClientSession] = None, headless: bool = True)
Description

Uses aiohttp requests to stalk a prime league group.

Also contains an extra case for the swiss starter group. :param prime_league_group_link: A valid link to a prime league group. :type prime_league_group_link: str :param session: When a session already exits, it should be reused as much as possible for better performance. :type session: aiohttp.ClientSession :param headless: The swiss starter group regroup requires the selenium webriver. Use for debugging. :type headless: bool :return: TeamList object containing all gathered information. :rtype: TeamList

async PykeBot2.backend.stalker.prime_league.stalk_prime_league_season(prime_league_season_link: str, headless=True)
Description

Uses Selenium to open the link and gather all group links from it,

further calls stalk prime league group on all groups. :param prime_league_season_link: A valid link to a prime league season. :type prime_league_season_link: str :param headless: Whether the browser should be headless or not. Use head for debugging purposes. :type headless: bool :return: TeamListList object containing all gathered information. :rtype: TeamListList

async PykeBot2.backend.stalker.prime_league.stalk_prime_league_team(prime_league_team_link: str, session: Optional[aiohttp.client.ClientSession] = None)
Description

Uses aiohttp requests to stalk a prime league team.

Parameters
  • prime_league_team_link

  • session (aiohttp.ClientSession) – When a session already exits, it should be reused as much as possible for better performance.

Returns

Team object containing all the gathered information.

Return type

Team

PykeBot2.backend.stalker.riot_api_rank module

Uses the riot api to fetch the ranks of players

author

Jonathan Decker

class PykeBot2.backend.stalker.riot_api_rank.RateLimiter(session: aiohttp.client.ClientSession)

Bases: object

add_new_tokens()
async get(*args, **kwargs)
max_tokens = 500
rate = 50
regen_after = 60.0
request_counter = 0
start_time = 0
async wait_for_tokens()
async PykeBot2.backend.stalker.riot_api_rank.add_player_rank(player: PykeBot2.models.data_models.Player, api_token: str, session=None)
Description

Calls stalk player riot using the summoner name of the given Player and adds a Rank obj to the Player.

Parameters
  • player (Player) – A Player obj with a summoner name.

  • api_token (str) – Valid Riot api token.

  • session (aiohttp.ClientSession or RateLimiter) – When a session already exits, it should be reused as much as possible for better performance.

Returns

None

Return type

None

async PykeBot2.backend.stalker.riot_api_rank.add_team_list_list_ranks(team_list_list: PykeBot2.models.data_models.TeamListList, api_token: str, session=None)
Description

Calls add team list ranks for each team list in the given team list list obj.

Parameters
  • team_list_list (TeamListList) – A team list list with a list of team lists.

  • api_token (str) – Valid Riot api token.

  • session (aiohttp.ClientSession or RateLimiter) – When a session already exits, it should be reused as much as possible for better performance.

Returns

None

Return type

None

async PykeBot2.backend.stalker.riot_api_rank.add_team_list_ranks(team_list: PykeBot2.models.data_models.TeamList, api_token: str, session=None)
Description

Calls add team ranks for each team in the given team list obj.

Parameters
  • team_list (TeamList) – A team list with a list of teams.

  • api_token (str) – Valid Riot api token.

  • session (aiohttp.ClientSession or RateLimiter) – When a session already exits, it should be reused as much as possible for better performance.

Returns

None

Return type

None

async PykeBot2.backend.stalker.riot_api_rank.add_team_ranks(team: PykeBot2.models.data_models.Team, api_token: str, session=None)
Description

Calls add player rank for each player of the given team. Also sets the average and max team rank.

Parameters
  • team (Team) – A team with a list of players.

  • api_token (str) – Valid Riot api token.

  • session (aiohttp.ClientSession or RateLimiter) – When a session already exits, it should be reused as much as possible for better performance.

Returns

None

Return type

None

PykeBot2.backend.stalker.riot_api_rank.calc_average_and_max_team_rank(team: PykeBot2.models.data_models.Team)
Description

Calculates the average and maximum rank of a given team.

If a player is unranked or the rank is unknown, then the player is ignored for the average. :param team: A team obj with players who have Rank objs. :type team: Team :return: None :rtype: None

async PykeBot2.backend.stalker.riot_api_rank.stalk_player_riot_api(sum_name: str, api_token: str, session=None) str

Uses the riot api to find the soloQ ranking of the given player. :param sum_name: Summoner name of the player. :type sum_name: str :param api_token: Valid Riot api token. :type api_token: str :param session: When a session already exits, it should be reused as much as possible for better performance. :type session: aiohttp.ClientSession or RateLimiter :return: String representation of the rank of the player. :rtype: str

PykeBot2.backend.stalker.summoners_inn module

Handles scraping of summoners inn with focus on the hausarrest cup. :author: Jonathan Decker

Helper function to filter out non team links. :param link: Str, a web link :return: Bool, true if the link contains a teams, false if not

async PykeBot2.backend.stalker.summoners_inn.stalk_summoners_inn_cup(summoners_inn_cup_link: str, session: Optional[aiohttp.client.ClientSession] = None)

Takes a link to a summoners inn cup, extracts all team links and uses the prime league team stalker, to stalk the teams. :param summoners_inn_cup_link: A valid link to a summoners inn cup like Hausarrest. :type summoners_inn_cup_link: str :param session: A reusable ClientSession :type session: aiohttp.ClientSession :return: A team list containing all teams of the cup. :rtype: TeamList

PykeBot2.backend.stalker.toornament module

Handles scraping of the toornament page. :author: Jonathan Decker

async PykeBot2.backend.stalker.toornament.stalk_toornament_team(toornament_team_link: str, session: Optional[aiohttp.client.ClientSession] = None)

Stalks all players in the given team and returns a Team Object :raises ServerErrorResponseError, NotFoundResponseError :param toornament_team_link: Link to a toornament team page :type toornament_team_link: str :param session: A session that can be reused, if none is given, a new one will be created :type session: aiohttp.ClientSession :return: team containing all players of the given team :rtype: Team

async PykeBot2.backend.stalker.toornament.stalk_toornament_tournament(toornament_link: str)

Stalks all teams signed up for the given toornament and returns a TeamList Object :raises ServerErrorResponseError, NotFoundResponseError :param toornament_link: url to a tournament on toornament :type toornament_link: str :return: TeamList, containing the Team obj for each signed up team :rtype: TeamList

PykeBot2.backend.stalker.toornament_api module

Handles scraping of the toornament page using the official toornament API.

author

Jonathan Decker

PykeBot2.backend.stalker.toornament_api.fetch_groups(toornament_link: str, api_token: str)
PykeBot2.backend.stalker.toornament_api.fetch_matches(toornament_link: str, api_token: str)
PykeBot2.backend.stalker.toornament_api.fetch_participants(toornament_link: str, api_token: str) List[dict]
PykeBot2.backend.stalker.toornament_api.fetch_stages(toornament_link: str, api_token: str)
PykeBot2.backend.stalker.toornament_api.fetch_tournament(toornament_link: str) str
PykeBot2.backend.stalker.toornament_api.parse_participants(participants: List[dict], tournament_name: str) PykeBot2.models.data_models.TeamList

Parses the given participant list and tournament name to create a TeamList object. :param participants: Expects a participant list created from the toornament api. :type participants: list[dict] :param tournament_name: The name of the tournament. :type tournament_name: str :return: A TeamList object created from the given participant list and tournament name. :rtype: TeamList

async PykeBot2.backend.stalker.toornament_api.stalk_toornament_api_tournament(toornament_link: str) PykeBot2.models.data_models.TeamList

Stalks teams in the given toornament link using the toornament api. A valid token in a file called ToornamentToken must be in the working directory for this. :param toornament_link: A valid link to a toornament tournament :type toornament_link: str :return: A TeamList object containing all teams from the given tournament :rtype: TeamList

Module contents