Exemple #1
0
  def show_round_end_rank(self) -> None:
    """Mostra a colocação dos jogadores no final da partida."""
    h3_status = self.driver.find_element_by_xpath(Constants.ScorePanel.h3).text.upper()
    ranks = []
    if h3_status == 'RANKING DA RODADA':
      for x in range(1, 15):
        try:
          position = self.driver.find_element_by_xpath(Constants.RankPanel.position(x)).text
          nick = self.driver.find_element_by_xpath(Constants.RankPanel.nick(x)).text
          points = self.driver.find_element_by_xpath(Constants.RankPanel.points(x)).text
          if nick:
            ranks.append([f'{position}º', nick, points])
        except NoSuchElementException:
          break
        except Exception as e:
          log_error('Round End', e)
      print('\n- Ranking da Rodada -\n', tabulate(ranks, ('Pos', 'Jogador', 'Pontos')))

    elif h3_status == 'FIM DE JOGO!' or \
            self.driver.find_element_by_xpath(Constants.ScorePanel.h4).text.upper() == 'RANKING FINAL':
      for x in range(1, 4):
        try:
          ranks.append([
            self.driver.find_element_by_xpath(Constants.ScorePanel.nick(x)).text,
            self.driver.find_element_by_xpath(Constants.ScorePanel.points(x)).text
          ])
        except NoSuchElementException:
          break
        except Exception as e:
          log_error('Game End', e)
          break
      print('- Fim de Jogo -\n', tabulate(ranks, ('Nome', 'Pontos')))
    print('')
Exemple #2
0
 def detect_round_end(self) -> None:
   """Detecta se é o final da rodada/partida para mostrar a colocação dos jogadores"""
   try:
     if self.driver.find_element_by_xpath(Constants.trophy):
       self.show_round_end_rank()
   except NoSuchElementException:
     pass
   except Exception as e:
     log_error('Round End Rank', e)
Exemple #3
0
 def try_auto_ready(self) -> None:
   """Pressiona o botão de pronto automaticamente"""
   try:
     if self.auto_ready and self.driver.find_element_by_xpath(
             Constants.ready_button).text.upper() == 'ESTOU PRONTO':
       self.driver.find_element_by_xpath(Constants.yellow_button_clickable).click()
   except NoSuchElementException:
     pass
   except Exception as e:
     log_error('Auto Ready', e)
Exemple #4
0
 def afk_detector(self) -> None:
   """Detecta o balão de inatividade para confirmar a presença"""
   try:
     if self.driver.find_element_by_xpath(Constants.afk_button_xpath):
       WebDriverWait(self.driver, 2).until(ec.element_to_be_clickable((By.XPATH, Constants.afk_button_xpath)))
       self.driver.find_element_by_xpath(Constants.afk_button_xpath).click()
     elif self.driver.find_elements_by_xpath(Constants.afk_box):
       pass
   except NoSuchElementException:
     pass
   except Exception as e:
     log_error('AFK Detector', e)
Exemple #5
0
 def get_equivalent_answers(self, letter: str, category: str) -> Optional[list[str]]:
   """
   Retorna todas as respostas possiveis com as categorias equivalentes.
   :param letter: letra incial.
   :param category: categoria.
   :return: lista com as respostas | None
   """
   try:
     normal_answers = self.dictionary[letter][category] if category != 'nome' else []
     return list({*normal_answers,
                  *list(itertools.chain(*[self.dictionary[letter][equiva] for equiva in EQUIVALENTS[category]]))})
   except Exception as e:
     log_error('Get equivalent answers', e)
     return None
Exemple #6
0
 def find_letter(self) -> Optional[str]:
   """
   Procura a letra atual da partida.
   :return: letra se encontrada | None
   """
   try:
     letter = self.driver.find_element_by_xpath(Constants.letter).text.lower()
     print(f'Letra Atual: {letter if letter else "?"}')
     return letter
   except NoSuchElementException:
     return None
   except Exception as e:
     log_error('Find letter', e)
     return None
Exemple #7
0
 def detect_button_state(self) -> None:
   """Detecta o estado do botão para executar as ações de acordo"""
   try:
     letter = self.find_letter()
     if letter:
       button = self.driver.find_element_by_xpath(Constants.yellow_button).text.upper()
       if button == 'STOP!':
         self.auto_complete(letter)
         if self.auto_stop:
           self.do_stop(letter)
       elif button == 'AVALIAR' and self.validator_type != 'null':
         self.validate(letter)
   except NoSuchElementException:
     pass
   except Exception as e:
     log_error('Main', e)
Exemple #8
0
 def check():
   """Avaliará as respostas com base no dicionario e negará as outras."""
   print('Avaliando Respostas...')
   category = self.driver.find_element_by_xpath(Constants.AnswerPanel.category).text
   category = re.sub('TEMA: ', '', category).lower()
   for x in range(1, 15):
     try:
       if self.driver.find_element_by_xpath(Constants.AnswerPanel.label_status(x)).text.upper() == 'VALIDADO!':
         category_answer = self.driver.find_element_by_xpath(Constants.AnswerPanel.label_answer(x)).text.lower()
         if category in EQUIVALENTS and self.use_equivalence:
           answers = self.get_equivalent_answers(letter, category)
         else:
           answers = self.dictionary[letter][category]
         if category_answer not in answers:
           self.driver.find_element_by_xpath(Constants.AnswerPanel.label_clickable(x)).click()
     except NoSuchElementException:
       continue
     except Exception as e:
       log_error('Validate', e)
   self.driver.find_element_by_xpath(Constants.yellow_button_clickable).click()
Exemple #9
0
 def auto_complete(self, letter: str) -> None:
   """
   Completa os campos com suas respectivas categorias.
   :param letter: letra atual.
   """
   print('Auto Completando...')
   for x in range(1, 13):
     try:
       field_input = self.driver.find_element_by_xpath(Constants.FormPanel.field_input(x)).get_attribute('value')
       if not field_input:
         field_category = self.driver.find_element_by_xpath(Constants.FormPanel.field_category(x)).text.lower()
         if field_category:
           if field_category in EQUIVALENTS and self.use_equivalence:
             answer = random_from_list(self.get_equivalent_answers(letter, field_category))
           else:
             answer = self.get_answer(letter, field_category)
           if answer:
             self.driver.find_element_by_xpath(Constants.FormPanel.field_input(x)).send_keys(answer)
     except (NoSuchElementException, AttributeError):
       continue
     except Exception as e:
       log_error('Auto Complete', e)
Exemple #10
0
  def show_game_info(self) -> None:
    """Mostrar o round atual e o total"""
    try:
      rounds = self.driver.find_element_by_xpath(Constants.rounds).text
      total = self.driver.find_element_by_xpath(Constants.rounds_total).text
      print(f'Rodadas: {rounds}{total}')
    except NoSuchElementException:
      pass
    except Exception as e:
      log_error('Game Info', e)

    players = []
    for x in range(1, 15):
      try:
        nick = self.driver.find_element_by_xpath(Constants.PlayerList.nick(x)).text
        points = self.driver.find_element_by_xpath(Constants.PlayerList.points(x)).text
        if nick:
          players.append([nick, points])
      except NoSuchElementException:
        break
      except Exception as e:
        log_error('Player List', e)
        break
    print('- Jogadores -\n', tabulate(players, ('Nome', 'Pontos')))