bcpkgfox 0.16.55__py3-none-any.whl → 0.16.57__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bcpkgfox might be problematic. Click here for more details.
- bcpkgfox/invoke_api.py +268 -0
- {bcpkgfox-0.16.55.dist-info → bcpkgfox-0.16.57.dist-info}/METADATA +1 -1
- {bcpkgfox-0.16.55.dist-info → bcpkgfox-0.16.57.dist-info}/RECORD +6 -6
- {bcpkgfox-0.16.55.dist-info → bcpkgfox-0.16.57.dist-info}/WHEEL +0 -0
- {bcpkgfox-0.16.55.dist-info → bcpkgfox-0.16.57.dist-info}/entry_points.txt +0 -0
- {bcpkgfox-0.16.55.dist-info → bcpkgfox-0.16.57.dist-info}/top_level.txt +0 -0
bcpkgfox/invoke_api.py
CHANGED
|
@@ -161,3 +161,271 @@ def invoke_api_proc_log(link, id_robo, token):
|
|
|
161
161
|
responseinsert = requests.request(
|
|
162
162
|
"POST", link, json=payload, headers=headers)
|
|
163
163
|
print(f"\n{responseinsert.json()}")
|
|
164
|
+
|
|
165
|
+
def login_2fac(driver, certificate, system, token, code_timeout=60):
|
|
166
|
+
from . import mostrar_mensagem
|
|
167
|
+
import time
|
|
168
|
+
import requests
|
|
169
|
+
import pyautogui
|
|
170
|
+
from selenium.webdriver.common.by import By
|
|
171
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
172
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
173
|
+
|
|
174
|
+
class login_2fac:
|
|
175
|
+
def __init__(self):
|
|
176
|
+
self.certificate = certificate
|
|
177
|
+
self.system = system
|
|
178
|
+
self.token = token
|
|
179
|
+
self.code_timeout = code_timeout
|
|
180
|
+
self.driver = driver
|
|
181
|
+
|
|
182
|
+
class tools(login_2fac):
|
|
183
|
+
def find_element_with_wait(self, by, value, timeout=10):
|
|
184
|
+
global driver
|
|
185
|
+
return WebDriverWait(
|
|
186
|
+
self.driver, timeout).until(
|
|
187
|
+
EC.presence_of_element_located(
|
|
188
|
+
(by, value)))
|
|
189
|
+
|
|
190
|
+
def find_elements_with_wait(self, by, value, timeout=10):
|
|
191
|
+
return WebDriverWait(
|
|
192
|
+
self.driver, timeout).until(
|
|
193
|
+
EC.presence_of_all_elements_located(
|
|
194
|
+
(by, value)))
|
|
195
|
+
|
|
196
|
+
class invokes_whoom(login_2fac):
|
|
197
|
+
def __init__(self):
|
|
198
|
+
super().__init__()
|
|
199
|
+
|
|
200
|
+
self.list_codes = []
|
|
201
|
+
|
|
202
|
+
def invoke_get_codes(self):
|
|
203
|
+
|
|
204
|
+
url = "https://api-4.bcfox.com.br/bcjur/views/codigo-validacao"
|
|
205
|
+
headers = {"x-access-token": self.token}
|
|
206
|
+
|
|
207
|
+
max_attempts = 5
|
|
208
|
+
for attempt in range(1, max_attempts + 1):
|
|
209
|
+
try:
|
|
210
|
+
response = requests.get(url, headers=headers)
|
|
211
|
+
response.raise_for_status() # Lança uma exceção se a resposta não for bem-sucedida
|
|
212
|
+
|
|
213
|
+
self.list_codes = response.json()
|
|
214
|
+
# print(self.list_codes)
|
|
215
|
+
return self.list_codes
|
|
216
|
+
|
|
217
|
+
except Exception as e:
|
|
218
|
+
print(f'Tentativa {attempt} falhou: {e}')
|
|
219
|
+
|
|
220
|
+
if attempt < max_attempts:
|
|
221
|
+
print('Tentando novamente em 5 segundos...')
|
|
222
|
+
time.sleep(5)
|
|
223
|
+
continue
|
|
224
|
+
else:
|
|
225
|
+
raise('Todas as tentativas falharam!')
|
|
226
|
+
|
|
227
|
+
def invoke_update_status(self, id):
|
|
228
|
+
|
|
229
|
+
url = f"https://api-4.bcfox.com.br/bcjur/views/codigo-validacao/{id}"
|
|
230
|
+
headers = {"x-access-token": self.token}
|
|
231
|
+
|
|
232
|
+
max_attempts = 5
|
|
233
|
+
for attempt in range(1, max_attempts + 1):
|
|
234
|
+
try:
|
|
235
|
+
responseinsert = requests.put(url, headers=headers)
|
|
236
|
+
responseinsert.raise_for_status() # Lança uma exceção se a resposta não for bem-sucedida
|
|
237
|
+
|
|
238
|
+
print(responseinsert)
|
|
239
|
+
return responseinsert
|
|
240
|
+
|
|
241
|
+
except Exception as e:
|
|
242
|
+
print(f'Tentativa {attempt} falhou: {e}')
|
|
243
|
+
|
|
244
|
+
if attempt < max_attempts:
|
|
245
|
+
print('Tentando novamente em 5 segundos...')
|
|
246
|
+
time.sleep(5)
|
|
247
|
+
continue
|
|
248
|
+
else:
|
|
249
|
+
raise('Todas as tentativas falharam!')
|
|
250
|
+
|
|
251
|
+
class whoom_codes(login_2fac):
|
|
252
|
+
def __init__(self):
|
|
253
|
+
super().__init__()
|
|
254
|
+
|
|
255
|
+
def codes_2_fac(self):
|
|
256
|
+
|
|
257
|
+
self.extension_check()
|
|
258
|
+
time.sleep(3)
|
|
259
|
+
|
|
260
|
+
try:
|
|
261
|
+
tools.find_element_with_wait(By.XPATH, '//input[@placeholder="Digite ou selecione um sistema pra acessar"]', timeout=10).send_keys(self.system)
|
|
262
|
+
code_insertion = True
|
|
263
|
+
|
|
264
|
+
except:
|
|
265
|
+
self.driver.get('chrome-extension://lnidijeaekolpfeckelhkomndglcglhh/index.html')
|
|
266
|
+
# Request the code
|
|
267
|
+
for _ in range(50): # Wait the extension to load
|
|
268
|
+
|
|
269
|
+
try:
|
|
270
|
+
tools.find_element_with_wait(By.XPATH, '//*[@id="root"]/div/div[1]/div//div//input', timeout=1).send_keys('eliezer@bcfox.com.br')
|
|
271
|
+
|
|
272
|
+
break
|
|
273
|
+
except:
|
|
274
|
+
self.driver.get('chrome-extension://lnidijeaekolpfeckelhkomndglcglhh/index.html')
|
|
275
|
+
|
|
276
|
+
tools.find_element_with_wait(By.XPATH, '//button').click()
|
|
277
|
+
|
|
278
|
+
# Attempts the new codes until success or requests limit
|
|
279
|
+
for _ in range(code_timeout):
|
|
280
|
+
responses = api.invoke_get_codes()
|
|
281
|
+
|
|
282
|
+
# Try new codes
|
|
283
|
+
code_insertion = False
|
|
284
|
+
for response in responses:
|
|
285
|
+
|
|
286
|
+
CODE = response['CODIGO']
|
|
287
|
+
ID = response['ID']
|
|
288
|
+
|
|
289
|
+
tools.find_element_with_wait(By.XPATH, '//input[@type="password"]').send_keys(CODE)
|
|
290
|
+
tools.find_element_with_wait(By.XPATH, '//div/div[2]/button').click()
|
|
291
|
+
|
|
292
|
+
# Check the code result
|
|
293
|
+
for _ in range(7):
|
|
294
|
+
|
|
295
|
+
# Correct
|
|
296
|
+
try:
|
|
297
|
+
# input('\n\n > Selecione o sistema e aperte alguma tecla.')
|
|
298
|
+
tools.find_element_with_wait(By.XPATH, '//input[@placeholder="Digite ou selecione um sistema pra acessar"]', timeout=1).send_keys(self.system)
|
|
299
|
+
api.invoke_update_status(ID) #FIX: Update
|
|
300
|
+
code_insertion = True
|
|
301
|
+
break
|
|
302
|
+
|
|
303
|
+
except:
|
|
304
|
+
pass
|
|
305
|
+
|
|
306
|
+
# Wrong
|
|
307
|
+
try:
|
|
308
|
+
tools.find_element_with_wait(By.XPATH, "//span[contains(text(), 'Senha inválida')]", timeout=1)
|
|
309
|
+
tools.find_element_with_wait(By.XPATH, "//button[text()='Voltar']", timeout=1)
|
|
310
|
+
code_insertion = False
|
|
311
|
+
break
|
|
312
|
+
|
|
313
|
+
except:
|
|
314
|
+
pass
|
|
315
|
+
|
|
316
|
+
# If the 'new_response' loop succeeds immediately
|
|
317
|
+
if not responses:
|
|
318
|
+
time.sleep(1)
|
|
319
|
+
|
|
320
|
+
if code_insertion:
|
|
321
|
+
break
|
|
322
|
+
|
|
323
|
+
if not(code_insertion):
|
|
324
|
+
mostrar_mensagem('Código WHOOM não chegou dentro do timeout estabelecido')
|
|
325
|
+
raise TimeoutError('Código WHOOM não chegou dentro do timeout estabelecido')
|
|
326
|
+
|
|
327
|
+
# Selects the system to access
|
|
328
|
+
try:
|
|
329
|
+
lines = self.find_elements_with_wait(self.driver, By.XPATH, '//*[@id="root"]/div[2]/div/div[1]/div/div[2]/div/div/div', timeout=5)
|
|
330
|
+
except:
|
|
331
|
+
try:
|
|
332
|
+
lines = self.find_elements_with_wait(self.driver, By.XPATH, '//*[@id="root"]/div[2]/div/div[2]/div/div[2]/div/div/div', timeout=5)
|
|
333
|
+
except Exception as e:
|
|
334
|
+
mostrar_mensagem('Não conseguiu achar o sistema no certificado')
|
|
335
|
+
print(f'{e}\n\n\n\n\n\n')
|
|
336
|
+
raise ValueError('Não conseguiu achar o sistema no certificado') from e
|
|
337
|
+
|
|
338
|
+
finded = False
|
|
339
|
+
div_list = []
|
|
340
|
+
|
|
341
|
+
# This loop extract the lines with the system name
|
|
342
|
+
for line in lines:
|
|
343
|
+
|
|
344
|
+
titulo_element = line.find_elements(By.XPATH, './span[*[name()="svg"]]')
|
|
345
|
+
|
|
346
|
+
if not titulo_element and not finded:
|
|
347
|
+
continue
|
|
348
|
+
|
|
349
|
+
elif titulo_element and not finded:
|
|
350
|
+
titulo_text = line.find_element(By.XPATH, './span').text
|
|
351
|
+
if self.certificate.lower().strip() in titulo_text.lower().strip():
|
|
352
|
+
finded = True
|
|
353
|
+
continue
|
|
354
|
+
|
|
355
|
+
elif not titulo_element and finded:
|
|
356
|
+
div_list.append(line)
|
|
357
|
+
|
|
358
|
+
elif titulo_element and finded:
|
|
359
|
+
break
|
|
360
|
+
|
|
361
|
+
if not div_list:
|
|
362
|
+
mostrar_mensagem('Não conseguiu achar o sistema no certificado')
|
|
363
|
+
raise ValueError('Não conseguiu achar o sistema no certificado')
|
|
364
|
+
|
|
365
|
+
if len(div_list) == 1:
|
|
366
|
+
div_list[0].click()
|
|
367
|
+
|
|
368
|
+
# Just do this loop if there are more than one system
|
|
369
|
+
else:
|
|
370
|
+
for div in div_list:
|
|
371
|
+
div_text = div.find_element(By.XPATH, './span').text
|
|
372
|
+
if self.system.lower().strip() not in div_text.lower().strip():
|
|
373
|
+
div_list.remove(div)
|
|
374
|
+
|
|
375
|
+
if len(div_list) == 1:
|
|
376
|
+
div_list[0].click()
|
|
377
|
+
else:
|
|
378
|
+
mostrar_mensagem('Mais de um sistema encontrado, verifique o nome do sistema no WHOOM e coloque um nome único na função')
|
|
379
|
+
raise ValueError('Mais de um sistema encontrado, verifique o nome')
|
|
380
|
+
|
|
381
|
+
# Verifies if the system was opened
|
|
382
|
+
num_windows = len(self.driver.window_handles)
|
|
383
|
+
for _ in range(5):
|
|
384
|
+
time.sleep(1)
|
|
385
|
+
if len(self.driver.window_handles) == num_windows:
|
|
386
|
+
tools.find_element_with_wait(By.XPATH, "//button[text()='Acessar']").click()
|
|
387
|
+
else:
|
|
388
|
+
break
|
|
389
|
+
|
|
390
|
+
def extension_check(self):
|
|
391
|
+
|
|
392
|
+
self.driver.get('chrome-extension://lnidijeaekolpfeckelhkomndglcglhh/index.html')
|
|
393
|
+
|
|
394
|
+
try:
|
|
395
|
+
tools.find_element_with_wait(By.XPATH, '//input[@placeholder="Digite ou selecione um sistema pra acessar"]', timeout=10).send_keys(self.system)
|
|
396
|
+
return
|
|
397
|
+
|
|
398
|
+
except Exception as e:
|
|
399
|
+
|
|
400
|
+
# Abrir uma nova aba
|
|
401
|
+
self.driver.execute_script("window.open('');")
|
|
402
|
+
|
|
403
|
+
# Fechar a aba original
|
|
404
|
+
self.driver.close()
|
|
405
|
+
|
|
406
|
+
# Mudar para a nova aba
|
|
407
|
+
self.driver.switch_to.window(self.driver.window_handles[-1])
|
|
408
|
+
|
|
409
|
+
time.sleep(1)
|
|
410
|
+
|
|
411
|
+
self.driver.get("https://chromewebstore.google.com/detail/whom-gerenciador-de-certi/lnidijeaekolpfeckelhkomndglcglhh")
|
|
412
|
+
|
|
413
|
+
try:
|
|
414
|
+
tools.find_element_with_wait(By.XPATH, "//span[contains(text(), 'Instalar') or contains(text(), 'Obter') or contains(text(), 'Add to Chrome')]").click()
|
|
415
|
+
except Exception as e:
|
|
416
|
+
return
|
|
417
|
+
time.sleep(5)
|
|
418
|
+
|
|
419
|
+
# Envia TAB e ENTER do teclado físico
|
|
420
|
+
pyautogui.press('tab')
|
|
421
|
+
time.sleep(0.5)
|
|
422
|
+
pyautogui.press('enter')
|
|
423
|
+
time.sleep(5)
|
|
424
|
+
|
|
425
|
+
self.driver.get('chrome-extension://lnidijeaekolpfeckelhkomndglcglhh/index.html')
|
|
426
|
+
|
|
427
|
+
tools = tools()
|
|
428
|
+
api = invokes_whoom()
|
|
429
|
+
bot = whoom_codes()
|
|
430
|
+
|
|
431
|
+
bot.codes_2_fac()
|
|
@@ -4,10 +4,10 @@ bcpkgfox/cli.py,sha256=6k4GNZimGKKkntuzy54EDKuvc_N0XKWr2N_Ho7nINxw,33497
|
|
|
4
4
|
bcpkgfox/exec_file.py,sha256=fl_Do2SlF7JuXazpNTod-e_0WZUk355fbd7ustQvi40,3728
|
|
5
5
|
bcpkgfox/find_elements.py,sha256=oeB-73LqMLoKchozPXuxRkThBju9IgUKqbgU-2AAq0s,23027
|
|
6
6
|
bcpkgfox/get_driver.py,sha256=ohimk9E2hL6T35IXv0XX0uvWDGCUZvZDlPMnuRjV1R0,30490
|
|
7
|
-
bcpkgfox/invoke_api.py,sha256=
|
|
7
|
+
bcpkgfox/invoke_api.py,sha256=N_6uMBAriCaqpZtyoQBmq4O0aHMlbJYFi-Dt3QDA3GY,16231
|
|
8
8
|
bcpkgfox/system.py,sha256=3lyOWx893T6KiAI-jDv7zAo3oKPf0Q5CLgZ8TeFd0Do,7901
|
|
9
|
-
bcpkgfox-0.16.
|
|
10
|
-
bcpkgfox-0.16.
|
|
11
|
-
bcpkgfox-0.16.
|
|
12
|
-
bcpkgfox-0.16.
|
|
13
|
-
bcpkgfox-0.16.
|
|
9
|
+
bcpkgfox-0.16.57.dist-info/METADATA,sha256=TukxOGLjhe2V7rsTpKxtP20aXzo6Iy5BDAQtC3F_FM0,1912
|
|
10
|
+
bcpkgfox-0.16.57.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
11
|
+
bcpkgfox-0.16.57.dist-info/entry_points.txt,sha256=qmaEg6K7Y0HOeaFo-G6lf44InGkeVI4I6hqobcY_nns,653
|
|
12
|
+
bcpkgfox-0.16.57.dist-info/top_level.txt,sha256=h01SqyYBEfS72vkRFOlEDZBUSu9pzU0bdX4m9hWNNmw,9
|
|
13
|
+
bcpkgfox-0.16.57.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|