async def get(self, sid: str = None, pipeline: str = None, keep_raw: bool = False, ptr_cache: PtrCache = None): '''Awaitable. Get this object from the pipeline.\n `sid` id identifying the session on the pipeline to reuse.\n `pipeline` key identifying the pipeline to execute against.\n `keep_raw` flag for storing raw data of the request as a dictionary.\n `ptr_cache` intercepts a PtrCache, usage details please refer to documentations.\n ''' self.set_pipeline(pipeline) token = await self.create_token() if ptr_cache: if not isinstance(ptr_cache, PtrCache): raise TypeError(f"'ptr_cache' receives object of type 'PtrCache', got '{ptr_cache.__class__.__name__}'") item = ptr_cache.get(token.stringify + self._meta.filter_key) if item: return item data = await self._meta.pipeline.get(token, sid) data = self._filter(data) if keep_raw: self._meta.raw_data = fast_copy(data) self._meta.data = self._transform(data) self._fill() if ptr_cache: ptr_cache.set(token.stringify + self._meta.filter_key, self) return self
async def iterate_match_events(): cache = PtrCache() match = await lol.MatchTimeline(id=3442099474).get() for team in match.teams: for p in team.participants: for event in p.timeline["events"]: pass
async def iterate_match_events(): # pylint: disable=unused-variable cache = PtrCache() match = await lol.Match(id=3442099474, include_timeline=True).get() for team in match.teams: for p in team.participants: # for event in p.timeline["events"]: for event in p.timeline.events: # try: # event.position.x # except Exception: pass pass
from typing import Dict, List, Mapping, Any, get_type_hints import pickle import re import json from pyot.pipeline.core import Pipeline from pyot.pipeline.token import PipelineToken from pyot.utils import PtrCache, camelcase, fast_copy from pyot.pipeline import pipelines normalizer_cache = PtrCache() typing_cache = PtrCache() class PyotLazyObject: obj: Any clas: Any def __init__(self, clas, obj, server_type, server): self.clas = clas self.server_map = [server_type, server] self.obj = obj def __call__(self): if issubclass(self.clas, PyotCoreObject): if isinstance(self.obj, list): li = [] for obj in self.obj: instance = self.clas() instance._meta.server_map = self.server_map instance._meta.data = instance._transform(obj)
from .__core__ import PyotCore, PyotStatic from pyot.utils.cdragon import cdragon_url, cdragon_sanitize from pyot.core.exceptions import NotFound from pyot.utils import PtrCache from functools import partial from typing import List, Iterator indexer = PtrCache() # PYOT CORE OBJECT class Item(PyotCore): id: int name: str description: str cleaned_description: str active: bool in_store: bool from_ids: List[int] to_ids: List[int] categories: List[str] maps: List[str] max_stacks: int modes: List[str] required_champion_key: str required_currency: str required_currency_cost: int special_recipe: int self_cost: int total_cost: int
async def clash(self, ctx: Context, *name: str): name = ''.join(name) summoner = await get_summoner(ctx, name) if not summoner: return buf = await summoner.clash_players.get() incomplete_clash_players = buf.players if not incomplete_clash_players: return await ctx.send( f'{summoner.name} doesnt belong to any clash team') team = await incomplete_clash_players[0].team.get() async with Gatherer() as gatherer: players_cache = PtrCache() match_history_cache = PtrCache() champions_cache = PtrCache() gatherer.statements = [player.summoner for player in team.players] players = await gatherer.gather() # type: list[lol.Summoner] for player in players: players_cache.set(player.id, player) statements = [ player.match_history.query(queue_ids=[700]) for player in players ] gatherer.statements = statements match_histories = await gatherer.gather( ) # type: list[lol.MatchHistory] for history in match_histories: match_history_cache.set(history.account_id, history) gatherer.statements = [player.profile_icon for player in players] await gatherer.gather() champion_set = set() most_played_champions = {} for match_history in match_histories: # type: lol.MatchHistory top_champs = match_history_most_played_champs( match_history)[:5] most_played_champions[match_history.account_id] = top_champs champion_set.update([champ for champ, times in top_champs]) statements = [lol.Champion(id=idx) for idx in champion_set] gatherer.statements = statements champions = await gatherer.gather() # type: list[lol.Champion] for champion in champions: champions_cache.set(champion.id, champion) for acc_id, champs in most_played_champions.items(): most_played_champions[acc_id] = [ (champions_cache.get(champ_id).name, n) for champ_id, n in champs ] team_embed = Embed() team_name = team.name if team.name else 'Team Name' team_tag = team.abbreviation if team.abbreviation else 'TAG' clash_icon = f'https://raw.communitydragon.org/latest/game/assets/clash/roster-logos/{team.icon_id}/1_64.png' team_embed.set_author(name=f'[{team_tag}] {team_name}', icon_url=clash_icon) team_embed.set_thumbnail(url=clash_icon) captain = players_cache.get( team.captain_summoner_id) # type: lol.Summoner team_data = [f'Captain: {captain.name}', f'Tier: {team.tier}'] team_embed.add_field(name='General info', value='\n'.join(team_data), inline=False) player_names: list[str] = [] player_lanes: list[tuple[str, str]] = [] player_embeds: list[Embed] = [] for clash_player_data in sorted( team.players, key=lambda x: lane_data[x.position]['sort_value']): player = players_cache.get( clash_player_data.summoner_id) # type: lol.Summoner position = clash_player_data.position match_history = match_history_cache.get( player.account_id) # type: lol.MatchHistory champs_played = most_played_champions[player.account_id] embed = await gather_summoner_data(player, position, match_history, champs_played) player_embeds.append(embed) player_names.append(player.name) player_lanes.append((player.name, clash_player_data.position)) player_roles = [ f'{name}: {lane_data[lane]["display_name"]}' for name, lane in player_lanes ] team_embed.add_field(name='Members', value='\n'.join(player_roles)) url_encoded_names = ",".join( [parse.quote(name) for name in player_names]) urls = { 'op.gg': f'https://eune.op.gg/multi/query={url_encoded_names}', 'u.gg': f'https://u.gg/multisearch?summoners={url_encoded_names}®ion=eun1', 'porofessor.gg': f'https://porofessor.gg/pregame/eune/{url_encoded_names}' } aliased_links = [f'[{site}]({url})' for site, url in urls.items()] team_embed.add_field(name='Third party sites', value='\n'.join(aliased_links), inline=False) await ctx.send(embed=team_embed) for embed in player_embeds: await ctx.send(embed=embed) refresh_op_gg_profiles(player_names)