Sorteador de time

from pyodide.http import pyfetch import asyncio import random import js from pyodide import JsProxy response = await pyfetch(url="https://valorant-api.com/v1/maps", method="GET") output = await response.json() api_agente = await pyfetch(url="https://valorant-api.com/v1/agents", method="GET") agente_saida = await api_agente.json() jogadores = [] div_atacantes = document.getElementById('nicks') def cadastrar(*args,**kwargs): jogadores.append(Element('name').value) div_jogador = document.createElement("div") div_jogador.setAttribute("id", f"div_{Element('name').value}") div_jogador.setAttribute("class", "jogador") div_atacantes.append(div_jogador) p_jogador = document.createElement("p") p_jogador.setAttribute("id", f"p_{Element('name').value}") botao = document.createElement("button") botao.setAttribute("id", f"btn_{Element('name').value}") botao.setAttribute("class", "btn") d_jogador = document.getElementById(f"div_{Element('name').value}") d_jogador.append(p_jogador) d_jogador.append(botao) nick = Element(f"p_{Element('name').value}") nick.write(Element('name').value) btn_inner = document.createElement("span") btn_inner.setAttribute("id", f"btn_inner_{Element('name').value}") btn_inner.setAttribute("class", "btn__inner") botao_jogador = document.getElementById(f"btn_{Element('name').value}") botao_jogador.append(btn_inner) btn_slide = document.createElement("span") btn_slide.setAttribute("class", "btn__slide") btn_content = document.createElement("span") btn_content.setAttribute("id", f"btn_content_{Element('name').value}") btn_content.setAttribute("class", "btn__content") id_btn_inner = document.getElementById(f"btn_inner_{Element('name').value}") id_btn_inner.append(btn_slide) id_btn_inner.append(btn_content) btn__content = Element(f"btn_content_{Element('name').value}") btn__content.write("X") document.getElementById('name').value='' def Sortear(proxy: JsProxy) -> None: timeA = [] timeB = [] random.shuffle(jogadores) for jogador in jogadores: if len(timeA) < (len(jogadores)/2): timeA.append(jogador) else: timeB.append(jogador) time_A = [timeA, sortear_personagem(timeA)] time_B = [timeB, sortear_personagem(timeB)] for jogador in range(len(timeA)): ataque = document.getElementById("ataque") div_jogador = document.createElement("div") div_jogador.setAttribute("id", f"jogador_{time_A[0][jogador]}") div_jogador.setAttribute("class", "jogador") div_img = document.createElement("div") div_img.setAttribute("class", "img") div_img.setAttribute("id", f"img_{time_A[0][jogador]}") div_nick = document.createElement("div") div_nick.setAttribute("class", "nick") div_nick.setAttribute("id", f"nick_{time_A[0][jogador]}") img_nick = document.createElement("img") img_nick.setAttribute("src", f"{time_A[1][jogador]['role']['displayIcon']}") p_nick = document.createElement("p") p_nick.setAttribute("id", f"p_nick_{time_A[0][jogador]}") div_nick.append(img_nick) div_nick.append(p_nick) div_jogador.append(div_img) div_jogador.append(div_nick) ataque.append(div_jogador) img_nome = document.getElementById(f"img_{time_A[0][jogador]}") img_nome.style.backgroundImage = f"url({time_A[1][jogador]['displayIcon']})" pyscript.write(f"p_nick_{time_A[0][jogador]}", time_A[0][jogador]) for jogador in range(len(timeB)): defesa = document.getElementById("defesa") div_jogador = document.createElement("div") div_jogador.setAttribute("id", f"jogador_{time_B[0][jogador]}") div_jogador.setAttribute("class", "jogador") div_img = document.createElement("div") div_img.setAttribute("class", "img") div_img.setAttribute("id", f"img_{time_B[0][jogador]}") div_nick = document.createElement("div") div_nick.setAttribute("class", "nick") div_nick.setAttribute("id", f"nick_{time_B[0][jogador]}") img_nick = document.createElement("img") img_nick.setAttribute("src", f"{time_B[1][jogador]['role']['displayIcon']}") p_nick = document.createElement("p") p_nick.setAttribute("id", f"p_nick_{time_B[0][jogador]}") div_nick.append(img_nick) div_nick.append(p_nick) div_jogador.append(div_img) div_jogador.append(div_nick) defesa.append(div_jogador) img_nome = document.getElementById(f"img_{time_B[0][jogador]}") img_nome.style.backgroundImage = f"url({time_B[1][jogador]['displayIcon']})" pyscript.write(f"p_nick_{time_B[0][jogador]}", time_B[0][jogador]) sortear_mapa() header = document.getElementById("header") header.style.display = "flex" main = document.getElementById("main") main.style.display = "flex" def sortear_mapa(): mapas = [] fundos = [] for valor in output['data']: if valor['displayName'] != 'The Range': mapas.append(valor['displayName']) fundos.append(valor['splash']) mapa_sorteado = random.randint(0, len(mapas)) pyscript.write("h1_mapa", f"{mapas[mapa_sorteado].upper()}") fundo_mapa = document.getElementById("mapa") fundo_mapa.style.backgroundImage = f"url({fundos[mapa_sorteado]})" def sortear_personagem(time): agentes = [] nomes = [] for valor in agente_saida['data']: agentes.append(valor) for agente in agentes: nomes.append(agente['displayName']) agentes_sorteados = [] while len(agentes_sorteados) < len(time): agentee = random.choice(nomes) if agente not in agentes_sorteados: for agente in agentes: if agente['displayName'] == agentee: agentes_sorteados.append(agente) return agentes_sorteados def Limpar(proxy: JsProxy) -> None: for jogador in jogadores: jogadores_cadastrados = document.getElementById(f"div_{jogador}") jogadores_cadastrados.remove() jogadores_main = document.getElementById(f"jogador_{jogador}") jogadores_main.remove() header = document.getElementById("header") header.style.display = "none" main = document.getElementById("main") main.style.display = "none" for jogador in range(len(jogadores)): jogadores.pop(-1)