def apply_runes(name: str, runes: Union[list[int], str]) -> list[str]: # Return error message if isinstance(runes, str): return [runes] # Build runepage s0 = _2style[runes[0]] data = { 'current': True, 'name': f'lt: {name}', 'primaryStyleId': s0, 'selectedPerkIds': runes, 'subStyleId': _2style[runes[4]]} # Submit to client if page := next((x for x in client.get_json('lol-perks/v1/pages') if x['name'].startswith('lt: ')), None): data = json.dumps(data | {'id': page['id']}) resp = client.put(f'lol-perks/v1/pages/{page["id"]}', data=data)
from operator import itemgetter from typing import Union import requests from loltui.client import client from loltui.output import * _headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'} _prunetbl = re.compile(r'<div class="perk-page__row">([\s\S]+?)</td>') _prune = re.compile(r'perk(Shard)?\/([0-9]+)\.png\?image=q_auto') _2style = [[(perk, style['id']) for slot in style['slots'] for perk in slot['perks']] for style in client.get_json('lol-perks/v1/styles')] _commonperks = set(map(itemgetter(0), _2style[0])).intersection( map(itemgetter(0), _2style[1])) _2style = dict(filter( lambda x: x[0] not in _commonperks, chain.from_iterable(_2style))) _2name = {perk['id']: perk['name'] for perk in client.get_json('lol-perks/v1/perks')} _cperk = {8000: 214, 8100: 9, 8200: 177, 8400: 154, 8300: 75, None: 251} def get_runes(champ: str, role: str) -> Union[list[int], str]: try: resp = requests.get( f'https://www.op.gg/champion/{champ}/statistics/{role}/rune', headers=_headers) except Exception as e:
def _get_gd_q() -> tuple[dict, str]: gd = client.get_json('lol-gameflow/v1/session')['gameData'] return gd, qdata[qid]['description'].removesuffix(' games') if ( qid := gd['queue']['id']) != -1 else 'Custom'
def get_team(): if (d := client.get_json( 'lol-champ-select/v1/session')) and 'myTeam' in d: return d['myTeam']
_pos = ['top', 'jungle', 'middle', 'utility', 'bottom'] def _get_champsel_session() -> Optional[Session]: ''' Champ selection: only teammates revealed, rune helper ''' def get_team(): if (d := client.get_json( 'lol-champ-select/v1/session')) and 'myTeam' in d: return d['myTeam'] def get_cids() -> Optional[list[int]]: if d := get_team(): return [x['championId'] for x in d] if d := get_team(): _, q = _get_gd_q() cs = client.get_json('lol-summoner/v1/current-summoner')['summonerId'] csi = next(i for i, x in enumerate(d) if x['summonerId'] == cs) cspos = next(x['assignedPosition'] for x in d if x['summonerId'] == cs) global _role _role = _pos.index(cspos) if cspos in _pos else None return Session(q, (len(d), 0), [x['summonerId'] for x in d], get_cids, cc_getter=itemgetter(csi)) # # Session retrieval # def _try_get_ses() -> Optional[Session]: if (gf := client.get('lol-gameflow/v1/gameflow-phase').content) == b'"ChampSelect"': return _get_champsel_session()