-
Notifications
You must be signed in to change notification settings - Fork 39
/
widgets.py
289 lines (247 loc) · 10.1 KB
/
widgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
from selenium.webdriver import FirefoxProfile, Firefox, DesiredCapabilities
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import undetected_chromedriver.v2 as Browser_uc
from selenium.webdriver.common.by import By
from typing import Tuple, List
import time, re
# Classes
class FirefoxBrowser(Firefox):
def __init__(self):
profile = FirefoxProfile()
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX
super().__init__(firefox_profile=profile, desired_capabilities=desired)
ChromeBrowser = Browser_uc.Chrome
# Abstrações
def rolar_pagina(browser: Firefox, valor: int):
browser.execute_script(f"window.scroll(0, window.pageYOffset + {valor})")
def login(wait: WebDriverWait, email: str, password: str):
apertar_botao(wait, ".hm-MainHeaderRHSLoggedOutWide_Login ")
preencher_campo(wait, ".lms-StandardLogin_Username ", email)
preencher_campo(wait, ".lms-StandardLogin_Password ", password)
apertar_botao(wait, ".lms-StandardLogin_LoginButton ")
def tirar_notificacoes(browser: Firefox, fast: WebDriverWait, wait: WebDriverWait):
try:
browser.switch_to.frame(encontra_elementos(wait, ".lp-UserNotificationsPopup_Frame ")[0])
apertar_botao(wait, "#remindLater")
try:
for _ in range(2):
apertar_botao(fast, ".pm-PushTargetedMessageOverlay_CloseButton ")
break
except: pass
except: pass
def devolve_jogos(wait: WebDriverWait) -> list:
return encontra_filhos(encontra_elementos(
wait, ".him-Classification ")[0], ".him-DetailsTwoWay ")
def filtra_tempo(jogo: WebElement, maximo: int) -> bool:
try:
hora_min = encontra_filhos(
jogo, ".him-InPlayTimer "
)[0].text
except: return False
tempo = int(hora_min.split(":")[0])
if tempo > maximo:
print("Passou do tempo requisitado:", maximo)
return False
return True
def tirar_aposta(wait: WebDriverWait):
try: apertar_botao(wait, ".bss-BetslipStandardModule_Minimised .bss-DefaultContent ")
except: pass
try:
apostas = encontra_elementos(wait, ".bss-NormalBetItem_DeleteContainer ")
except: return
for aposta in reversed(apostas):
if encontra_filhos(aposta, ".bss-StakeBox_StakeValue-empty ") != []:
try: encontra_filhos(aposta, ".bss-NormalBetItem_Remove")[0].click()
except: pass
try: apertar_botao(wait, ".bss-DefaultContent_Close ")
except: apertar_botao(wait, ".bsm-BetslipStandardModule_Overlay ")
def abrir_opcoes(wait: WebDriverWait):
time.sleep(6)
terminou = False
tentativas = 0
while not terminou and tentativas < 5:
terminou = True
botoes = encontra_elementos(wait, '[class="sip-MarketGroupButton "]')
for botao in botoes:
try: botao.click()
except:
tirar_aposta(wait)
terminou = False
tentativas += 1
break
def selecionar_info_tabela(opcao: WebElement, info: str, medida: str,
minOdd: float, search:str) -> WebElement or bool:
rowName = (".srb-ParticipantLabelCentered " if search == "table1"
else ".srb-ParticipantLabel_Name ")
row = -1
for index, linha in enumerate(
encontra_filhos(opcao, rowName)):
linha = linha.text.lower().strip()
if medida.lower() == linha:
row = index
break
if row == -1: return False
column = 0
info = re.escape(info).replace("X", "\d").lower()
for index, coluna in enumerate(
encontra_filhos(opcao, '.gl-MarketColumnHeader ')):
coluna = coluna.text.lower()
if re.search(info, coluna):
column = index
break
columnName = (".gl-ParticipantOddsOnly" if search == "table1"
else ".gl-Participant_General ")
botao = encontra_filhos(encontra_filhos(
opcao, ".gl-Market ")[column], columnName)[row]
texto_btn = botao.text.split()
if len(texto_btn) == 2: texto_btn = float(texto_btn[1])
else: texto_btn = float(texto_btn[0])
if texto_btn > minOdd: return botao
print(f"Odd inferior ao requerido: {texto_btn} < {minOdd}")
return False
def selecionar_info_tabela2(opcao: WebElement, info: str, medida: str,
minOdd: float) -> WebElement or bool:
column = 0
for index, coluna in enumerate(
encontra_filhos(opcao, '.gl-MarketColumnHeader ')):
if info.lower() in coluna.text.lower():
column = index
break
for index, linha in enumerate(
encontra_filhos(encontra_filhos(opcao, ".gl-Market "
)[column], ".gl-ParticipantCentered")):
texto, odd = linha.text.lower().strip().split()
if medida.lower() == texto:
botao = linha
if float(odd) > minOdd:
return botao
else:
print(f"Odd inferior ao requerido: {float(botao.text)} < {minOdd}")
break
return False
def seleciona_info_botoes(
opcao: WebElement, info: str, minOdd: float) -> WebElement or bool:
info = re.escape(info).replace("X", "\d").lower()
for coluna in encontra_filhos(opcao, ".gl-Participant_General "):
informacao, odd = coluna.text.split("\n")
if re.match(info, informacao.lower()):
if float(odd) > minOdd: return coluna
else:
print(f"Odd inferior ao requerido: {odd} < {minOdd}")
break
return False
def procura_aposta(opcao: WebElement, info: str or list,
minOdd: float, search: str) -> bool:
if search != "options":
coluna, medida = info
if search != "table2":
botao = selecionar_info_tabela(
opcao, coluna, medida, minOdd, search)
else:
botao = selecionar_info_tabela2(
opcao, coluna, medida, minOdd)
else:
botao = seleciona_info_botoes(opcao, info, minOdd)
if botao:
botao.click()
return True
return False
def procura_opcao(wait: WebDriverWait, nome: str) -> WebElement or bool:
nome = re.escape(nome).replace("X", "\d").lower() + "$"
opcoes = encontra_elementos(wait, '.sip-MarketGroup ')
for opcao in opcoes:
try:
titulo = encontra_filhos(opcao, '.sip-MarketGroupButton ')[0]
titulo = titulo.text.strip().lower().replace("º", "°")
if re.match(nome, titulo):
print("\nprocura_opcao:", titulo)
return opcao
except Exception as e: print(e)
return False
def adicionar_valor(
wait: WebDriverWait, fast: WebDriverWait, title:str, valor: float) -> bool:
atribuiu = False
if atribuir_valor_single(wait, title, valor): return True
try:
time.sleep(2)
apertar_botao(fast, ".bss-DefaultContent ")
except Exception as e: print(e)
try:
time.sleep(2)
atribuiu = atribuir_valor_multi(wait, title, valor)
except Exception as e: print(e)
try:
apertar_botao(fast, ".bss-DefaultContent_Close ")
except Exception as e: print(e)
return atribuiu
def atribuir_valor_multi(wait: WebDriverWait, title:str, valor: float) -> bool:
jogadas = encontra_elementos(wait,
".bss-NormalBetItem_ContentWrapper ")
title = re.escape(title).replace("X", "\d").lower().replace("°", "º")
for jogada in reversed(jogadas):
print(title, jogada.text.lower().strip())
if re.search(title, jogada.text.lower().strip()):
encontra_filhos(jogada,
".bss-StakeBox_StakeValueInput"
)[0].send_keys(str(valor))
return True
return False
def atribuir_valor_single(wait: WebDriverWait, title:str, valor: float) -> bool:
try:
title = re.escape(title).replace("X", "\d").lower().replace("°", "º")
text_jogada = encontra_elementos(wait, ".qbs-NormalBetItem_Details")[0].text
if re.search(title, text_jogada.lower().strip()):
preencher_campo(wait,".qbs-StakeBox_StakeInput ", str(valor))
return True
except Exception as e:
print(type(e), e)
return False
# Informações
def abrir_escanteios(wait: WebDriverWait) -> bool:
for opcao in encontra_elementos(wait, ".ipe-GridHeaderTabLink "):
if "Escanteios" in opcao.text:
opcao.click()
return True
return False
def banca(wait: WebElement) -> float:
texto_banca = encontra_elementos(
wait, ".hm-Balance ")[0].text
print("Banca:", texto_banca)
return float(texto_banca.strip("R$").replace(",", "."))
def nome_times(wait: WebDriverWait) -> Tuple[str]:
return encontra_elementos(
wait, ".ipe-EventHeader_Fixture"
)[0].text.split(" v ")
def numero_gols(jogo: WebElement) -> List[int]:
lista_gols = encontra_filhos(jogo,
".him-StandardScores_Scores "
)[0].text.split("\n")
return list(map(int, lista_gols))
def numero_escanteios(wait: WebDriverWait) -> int:
texto_escanteios = encontra_elementos(wait,
".sip-MarketGroup_Info ")[0].text
print(texto_escanteios)
return int(texto_escanteios.split()[-1])
# Base
def apertar_botao(wait: WebDriverWait, selector: str):
wait.until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, selector)
)).click()
def esperar_sumir(wait: WebDriverWait, selector: str):
wait.until(EC.invisibility_of_element(
(By.CSS_SELECTOR, selector)))
def preencher_campo(wait: WebDriverWait, selector: str, valor: str):
wait.until(EC.presence_of_element_located(
(By.CSS_SELECTOR, selector))
).send_keys(valor)
def encontra_filhos(element: WebElement, selector: str) -> List[WebElement]:
return element.find_elements_by_css_selector(selector)
def encontra_elementos(wait: WebDriverWait, selector: str) -> List[WebElement]:
return wait.until(
EC.presence_of_all_elements_located(
(By.CSS_SELECTOR, selector)))