btime-framework 0.1.0__tar.gz
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.
- btime_framework-0.1.0/Btime_framework.egg-info/PKG-INFO +54 -0
- btime_framework-0.1.0/Btime_framework.egg-info/SOURCES.txt +20 -0
- btime_framework-0.1.0/Btime_framework.egg-info/dependency_links.txt +1 -0
- btime_framework-0.1.0/Btime_framework.egg-info/entry_points.txt +4 -0
- btime_framework-0.1.0/Btime_framework.egg-info/requires.txt +35 -0
- btime_framework-0.1.0/Btime_framework.egg-info/top_level.txt +1 -0
- btime_framework-0.1.0/PKG-INFO +54 -0
- btime_framework-0.1.0/README.md +2 -0
- btime_framework-0.1.0/SeleniumTwo/__init__.py +430 -0
- btime_framework-0.1.0/SeleniumTwo/cli.py +862 -0
- btime_framework-0.1.0/SeleniumTwo/find_elements.py +618 -0
- btime_framework-0.1.0/SeleniumTwo/get_driver.py +701 -0
- btime_framework-0.1.0/SeleniumTwo/invoke_api.py +163 -0
- btime_framework-0.1.0/SeleniumTwo/system.py +255 -0
- btime_framework-0.1.0/setup.cfg +4 -0
- btime_framework-0.1.0/setup.py +67 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: btime-framework
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Btime Framework
|
|
5
|
+
Home-page: https://github.com/Btime/Btime_Framework
|
|
6
|
+
Author: Guilherme Neri
|
|
7
|
+
Author-email: guilherme.neri@btime.com.br
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: setuptools
|
|
14
|
+
Requires-Dist: pyperclip
|
|
15
|
+
Requires-Dist: pyinstaller
|
|
16
|
+
Requires-Dist: selenium
|
|
17
|
+
Provides-Extra: pynput
|
|
18
|
+
Requires-Dist: pynput; extra == "pynput"
|
|
19
|
+
Provides-Extra: screeninfo
|
|
20
|
+
Requires-Dist: screeninfo; extra == "screeninfo"
|
|
21
|
+
Provides-Extra: pywinauto
|
|
22
|
+
Requires-Dist: pywinauto; extra == "pywinauto"
|
|
23
|
+
Provides-Extra: capmonstercloudclient
|
|
24
|
+
Requires-Dist: capmonstercloudclient; extra == "capmonstercloudclient"
|
|
25
|
+
Provides-Extra: twocaptcha
|
|
26
|
+
Requires-Dist: 2captcha-python; extra == "twocaptcha"
|
|
27
|
+
Provides-Extra: full
|
|
28
|
+
Requires-Dist: undetected-chromedriver; extra == "full"
|
|
29
|
+
Requires-Dist: webdriver-manager; extra == "full"
|
|
30
|
+
Requires-Dist: opencv-python; extra == "full"
|
|
31
|
+
Requires-Dist: pygetwindow; extra == "full"
|
|
32
|
+
Requires-Dist: pyinstaller; extra == "full"
|
|
33
|
+
Requires-Dist: screeninfo; extra == "full"
|
|
34
|
+
Requires-Dist: pyscreeze; extra == "full"
|
|
35
|
+
Requires-Dist: pyautogui; extra == "full"
|
|
36
|
+
Requires-Dist: selenium; extra == "full"
|
|
37
|
+
Requires-Dist: requests; extra == "full"
|
|
38
|
+
Requires-Dist: pymupdf; extra == "full"
|
|
39
|
+
Requires-Dist: Pillow; extra == "full"
|
|
40
|
+
Requires-Dist: psutil; extra == "full"
|
|
41
|
+
Requires-Dist: pynput; extra == "full"
|
|
42
|
+
Dynamic: author
|
|
43
|
+
Dynamic: author-email
|
|
44
|
+
Dynamic: classifier
|
|
45
|
+
Dynamic: description
|
|
46
|
+
Dynamic: description-content-type
|
|
47
|
+
Dynamic: home-page
|
|
48
|
+
Dynamic: provides-extra
|
|
49
|
+
Dynamic: requires-dist
|
|
50
|
+
Dynamic: requires-python
|
|
51
|
+
Dynamic: summary
|
|
52
|
+
|
|
53
|
+
1° - Instale a lib:
|
|
54
|
+
pip install Btime_framework
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
Btime_framework.egg-info/PKG-INFO
|
|
4
|
+
Btime_framework.egg-info/SOURCES.txt
|
|
5
|
+
Btime_framework.egg-info/dependency_links.txt
|
|
6
|
+
Btime_framework.egg-info/entry_points.txt
|
|
7
|
+
Btime_framework.egg-info/requires.txt
|
|
8
|
+
Btime_framework.egg-info/top_level.txt
|
|
9
|
+
SeleniumTwo/__init__.py
|
|
10
|
+
SeleniumTwo/cli.py
|
|
11
|
+
SeleniumTwo/find_elements.py
|
|
12
|
+
SeleniumTwo/get_driver.py
|
|
13
|
+
SeleniumTwo/invoke_api.py
|
|
14
|
+
SeleniumTwo/system.py
|
|
15
|
+
btime_framework.egg-info/PKG-INFO
|
|
16
|
+
btime_framework.egg-info/SOURCES.txt
|
|
17
|
+
btime_framework.egg-info/dependency_links.txt
|
|
18
|
+
btime_framework.egg-info/entry_points.txt
|
|
19
|
+
btime_framework.egg-info/requires.txt
|
|
20
|
+
btime_framework.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
setuptools
|
|
2
|
+
pyperclip
|
|
3
|
+
pyinstaller
|
|
4
|
+
selenium
|
|
5
|
+
|
|
6
|
+
[capmonstercloudclient]
|
|
7
|
+
capmonstercloudclient
|
|
8
|
+
|
|
9
|
+
[full]
|
|
10
|
+
undetected-chromedriver
|
|
11
|
+
webdriver-manager
|
|
12
|
+
opencv-python
|
|
13
|
+
pygetwindow
|
|
14
|
+
pyinstaller
|
|
15
|
+
screeninfo
|
|
16
|
+
pyscreeze
|
|
17
|
+
pyautogui
|
|
18
|
+
selenium
|
|
19
|
+
requests
|
|
20
|
+
pymupdf
|
|
21
|
+
Pillow
|
|
22
|
+
psutil
|
|
23
|
+
pynput
|
|
24
|
+
|
|
25
|
+
[pynput]
|
|
26
|
+
pynput
|
|
27
|
+
|
|
28
|
+
[pywinauto]
|
|
29
|
+
pywinauto
|
|
30
|
+
|
|
31
|
+
[screeninfo]
|
|
32
|
+
screeninfo
|
|
33
|
+
|
|
34
|
+
[twocaptcha]
|
|
35
|
+
2captcha-python
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
SeleniumTwo
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: btime-framework
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Btime Framework
|
|
5
|
+
Home-page: https://github.com/Btime/Btime_Framework
|
|
6
|
+
Author: Guilherme Neri
|
|
7
|
+
Author-email: guilherme.neri@btime.com.br
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: setuptools
|
|
14
|
+
Requires-Dist: pyperclip
|
|
15
|
+
Requires-Dist: pyinstaller
|
|
16
|
+
Requires-Dist: selenium
|
|
17
|
+
Provides-Extra: pynput
|
|
18
|
+
Requires-Dist: pynput; extra == "pynput"
|
|
19
|
+
Provides-Extra: screeninfo
|
|
20
|
+
Requires-Dist: screeninfo; extra == "screeninfo"
|
|
21
|
+
Provides-Extra: pywinauto
|
|
22
|
+
Requires-Dist: pywinauto; extra == "pywinauto"
|
|
23
|
+
Provides-Extra: capmonstercloudclient
|
|
24
|
+
Requires-Dist: capmonstercloudclient; extra == "capmonstercloudclient"
|
|
25
|
+
Provides-Extra: twocaptcha
|
|
26
|
+
Requires-Dist: 2captcha-python; extra == "twocaptcha"
|
|
27
|
+
Provides-Extra: full
|
|
28
|
+
Requires-Dist: undetected-chromedriver; extra == "full"
|
|
29
|
+
Requires-Dist: webdriver-manager; extra == "full"
|
|
30
|
+
Requires-Dist: opencv-python; extra == "full"
|
|
31
|
+
Requires-Dist: pygetwindow; extra == "full"
|
|
32
|
+
Requires-Dist: pyinstaller; extra == "full"
|
|
33
|
+
Requires-Dist: screeninfo; extra == "full"
|
|
34
|
+
Requires-Dist: pyscreeze; extra == "full"
|
|
35
|
+
Requires-Dist: pyautogui; extra == "full"
|
|
36
|
+
Requires-Dist: selenium; extra == "full"
|
|
37
|
+
Requires-Dist: requests; extra == "full"
|
|
38
|
+
Requires-Dist: pymupdf; extra == "full"
|
|
39
|
+
Requires-Dist: Pillow; extra == "full"
|
|
40
|
+
Requires-Dist: psutil; extra == "full"
|
|
41
|
+
Requires-Dist: pynput; extra == "full"
|
|
42
|
+
Dynamic: author
|
|
43
|
+
Dynamic: author-email
|
|
44
|
+
Dynamic: classifier
|
|
45
|
+
Dynamic: description
|
|
46
|
+
Dynamic: description-content-type
|
|
47
|
+
Dynamic: home-page
|
|
48
|
+
Dynamic: provides-extra
|
|
49
|
+
Dynamic: requires-dist
|
|
50
|
+
Dynamic: requires-python
|
|
51
|
+
Dynamic: summary
|
|
52
|
+
|
|
53
|
+
1° - Instale a lib:
|
|
54
|
+
pip install Btime_framework
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
"""
|
|
2
|
+
**_Selenium_Two__Made_By_Neri - DOC_**
|
|
3
|
+
|
|
4
|
+
Args:
|
|
5
|
+
*DRIVER*: To use the driver service, initialize its class as in the example below. All explanations of the options are there.
|
|
6
|
+
- driver_class = SeleniumTwo.Instancedriver()
|
|
7
|
+
|
|
8
|
+
_SYSTEM_: If you want to extract PDFs, create folders, display message boxes, among other system services, use the command below **directly**.
|
|
9
|
+
- SeleniumTwo.System.{def}
|
|
10
|
+
|
|
11
|
+
_API_: To use APIs, use the command below, **directly**
|
|
12
|
+
- SeleniumTwo.invoke_api.{def}
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from selenium.webdriver.remote.webelement import WebElement
|
|
17
|
+
from selenium.webdriver.common.by import By
|
|
18
|
+
from typing import Optional
|
|
19
|
+
import tkinter as tk
|
|
20
|
+
import re
|
|
21
|
+
|
|
22
|
+
from .find_elements import *
|
|
23
|
+
from .invoke_api import *
|
|
24
|
+
from .get_driver import *
|
|
25
|
+
from .system import *
|
|
26
|
+
|
|
27
|
+
import os
|
|
28
|
+
|
|
29
|
+
dir_kit = "C:\\TMPIMGKIT\\LAST_IMG"
|
|
30
|
+
|
|
31
|
+
dirs_defaults = {
|
|
32
|
+
"dir_kit": "C:\\TMPIMGKIT\\LAST_IMG",
|
|
33
|
+
|
|
34
|
+
"dir_ggi": "C:\\TMPIMGGI\\LAST_IMG\\",
|
|
35
|
+
"dir_gi": "C:\\TMPIMGI\\",
|
|
36
|
+
|
|
37
|
+
"dir_robos": "C:\\TMP_ROBOS",
|
|
38
|
+
|
|
39
|
+
"dir_pe": "C:\\TMPIMGPE\\"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
dirs_sub = {
|
|
43
|
+
"dir_consulta": "C:\\TMPIMGCONSULTA\\",
|
|
44
|
+
"dir_GCPJ": "C:\\TMPIMGGCPJ\\",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
sub_pastas = ["LAST_IMG", "FTP", "ftp2", "validacao"]
|
|
48
|
+
|
|
49
|
+
driver = None
|
|
50
|
+
By = By
|
|
51
|
+
|
|
52
|
+
def get_page_source():
|
|
53
|
+
global driver
|
|
54
|
+
return driver.page_source
|
|
55
|
+
|
|
56
|
+
def create_dirs(specifics_dirs: Optional[list] = None, disable_print_response: bool = False) -> str:
|
|
57
|
+
""" Cria os diretórios padrões
|
|
58
|
+
- Caso queira criar algum especifico passe em forma de LISTA o caminho deles.
|
|
59
|
+
"""
|
|
60
|
+
global dirs
|
|
61
|
+
dirs_created = []
|
|
62
|
+
|
|
63
|
+
# Specifics
|
|
64
|
+
if specifics_dirs:
|
|
65
|
+
for dir_ in specifics_dirs:
|
|
66
|
+
if not os.path.exists(dir_):
|
|
67
|
+
os.makedirs(os.path.join(dir_, pasta))
|
|
68
|
+
dirs_created.append(os.path.join(dir_, pasta))
|
|
69
|
+
|
|
70
|
+
# Log
|
|
71
|
+
if disable_print_response == False:
|
|
72
|
+
if dirs_created:
|
|
73
|
+
print(f" {DK_ORANGE}>{RESET} {len(dirs_created)} Dirs createds:") if len(dirs_created) > 1 else print(f" {DK_ORANGE}>{RESET} {len(dirs_created)} Dir created:")
|
|
74
|
+
for pasta in dirs_created:
|
|
75
|
+
print(f" {ORANGE}>{RESET} {pasta}")
|
|
76
|
+
|
|
77
|
+
def resource_path(relative_path):
|
|
78
|
+
"""
|
|
79
|
+
Returns the absolute path of a resource, whether running normally or in a PyInstaller executable.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
relative_path (str): Relative path of the resource.
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
str: Absolute path of the resource.
|
|
86
|
+
"""
|
|
87
|
+
try: base_path = sys._MEIPASS
|
|
88
|
+
except AttributeError: base_path = os.path.abspath(".")
|
|
89
|
+
return os.path.join(base_path, relative_path)
|
|
90
|
+
|
|
91
|
+
def initialize_driver(extension_path: Optional[str] = None, captcha_name: Optional[str] = None, captcha_api_key: Optional[str] = None) -> WebElement:
|
|
92
|
+
|
|
93
|
+
""" Passe somente o nome da pasta, no mesmo diretório da main """
|
|
94
|
+
global driver, dir_kit
|
|
95
|
+
|
|
96
|
+
if driver is None:
|
|
97
|
+
driver = get_driver.backcode__dont_use__launch_browser(dir_kit, extension_path,
|
|
98
|
+
captcha_name, captcha_api_key)
|
|
99
|
+
|
|
100
|
+
print(driver)
|
|
101
|
+
return driver
|
|
102
|
+
|
|
103
|
+
def finalize_driver():
|
|
104
|
+
global driver
|
|
105
|
+
|
|
106
|
+
driver.quit()
|
|
107
|
+
driver = None
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
def get(link):
|
|
111
|
+
global driver
|
|
112
|
+
if driver != None:
|
|
113
|
+
get_driver.backcode__dont_use__get(driver, link)
|
|
114
|
+
|
|
115
|
+
def wait_for_element_be_clickable(by, value, timeout=10, parent=None):
|
|
116
|
+
global driver
|
|
117
|
+
if driver != None:
|
|
118
|
+
return find_elements.backcode__dont_use__wait_for_element_be_clickable(driver, by.lower(), value, timeout, parent)
|
|
119
|
+
|
|
120
|
+
else: raise ValueError("Error: Driver is None")
|
|
121
|
+
|
|
122
|
+
def find_element_with_wait(by, value, timeout=10, parent=None):
|
|
123
|
+
global driver
|
|
124
|
+
if driver != None:
|
|
125
|
+
return find_elements.backcode__dont_use__find_element_with_wait_backcode(driver, by.lower(), value, timeout, parent)
|
|
126
|
+
|
|
127
|
+
else: raise ValueError("Error: Driver is None")
|
|
128
|
+
|
|
129
|
+
def find_elements_with_wait(by, value, timeout=10, parent=None):
|
|
130
|
+
global driver
|
|
131
|
+
if driver != None:
|
|
132
|
+
return find_elements.backcode__dont_use__find_elements_with_wait_backcode(driver, by.lower(), value, timeout, parent)
|
|
133
|
+
|
|
134
|
+
else: raise ValueError("Error: Driver is None")
|
|
135
|
+
|
|
136
|
+
def wait_for_element_appear(object, type, timeout=10):
|
|
137
|
+
"""
|
|
138
|
+
Aguarda até que um objeto (texto, elemento ou imagem) seja encontrado na tela.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
object (str|list): O objeto a ser procurado. Pode ser um caminho de imagem, texto ou elemento XPATH.
|
|
142
|
+
type (str): O tipo de objeto a ser procurado. Pode ser 'imagem', 'texto' ou 'elemento'.
|
|
143
|
+
timeout (int): limite de tempo que vai procurar o objeto, coloque 0 para não ter limite
|
|
144
|
+
|
|
145
|
+
Exemplo:
|
|
146
|
+
wait_for('C:\\Caminho\\da\\imagem.png', 'imagem')
|
|
147
|
+
wait_for('Texto a ser encontrado', 'texto')
|
|
148
|
+
wait_for( XPATH_AQUI, 'elemento')
|
|
149
|
+
"""
|
|
150
|
+
global driver
|
|
151
|
+
tempo = timeout
|
|
152
|
+
|
|
153
|
+
text_type = ['texto', 'string', 'palavra', 'mensagem', 'frase', 'conteúdo', 'texto_visível', 'texto_encontrado', 'texto_display', 'label']
|
|
154
|
+
element_type = [ "element", "elemento", "botao", 'element', 'web_element', 'html_element', 'ui_element', 'interface_element', 'objeto', 'widget', 'campo', 'componente']
|
|
155
|
+
imagem_type = [ 'imagem', 'img', 'imagem_png', 'imagem_jpeg', 'image', 'imagem_exata', 'padrão_imagem', 'foto', 'captura_tela', 'screenshot', 'imagem_visual']
|
|
156
|
+
|
|
157
|
+
for escrita in text_type:
|
|
158
|
+
if escrita in type.lower():
|
|
159
|
+
type = "text"
|
|
160
|
+
|
|
161
|
+
for escrita in element_type:
|
|
162
|
+
if escrita in type.lower():
|
|
163
|
+
type = "element"
|
|
164
|
+
|
|
165
|
+
for escrita in imagem_type:
|
|
166
|
+
if escrita in type.lower():
|
|
167
|
+
type = "image"
|
|
168
|
+
|
|
169
|
+
return find_elements.backcode__dont_use__wait_for(driver, object, type, timeout=tempo)
|
|
170
|
+
|
|
171
|
+
def wait_for_element_disappear(object, type, timeout=10):
|
|
172
|
+
"""
|
|
173
|
+
Aguarda até que um objeto desapareça.(texto, elemento ou imagem)
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
object (str|list): O objeto a ser procurado. Pode ser um caminho de imagem, texto ou elemento XPATH.
|
|
177
|
+
type (str): O tipo de objeto a ser procurado. Pode ser 'imagem', 'texto' ou 'elemento'.
|
|
178
|
+
timeout (int): limite de tempo que vai procurar o objeto, coloque 0 para não ter limite
|
|
179
|
+
|
|
180
|
+
Exemplo:
|
|
181
|
+
wait_for('C:\\Caminho\\da\\imagem.png', 'imagem')
|
|
182
|
+
wait_for('Texto a ser encontrado', 'texto')
|
|
183
|
+
wait_for( XPATH_AQUI, 'elemento')
|
|
184
|
+
"""
|
|
185
|
+
global driver
|
|
186
|
+
tempo = timeout
|
|
187
|
+
|
|
188
|
+
text_type = ['texto', 'string', 'palavra', 'mensagem', 'frase', 'conteúdo', 'texto_visível', 'texto_encontrado', 'texto_display', 'label']
|
|
189
|
+
element_type = [ "element", "elemento", "botao", 'element', 'web_element', 'html_element', 'ui_element', 'interface_element', 'objeto', 'widget', 'campo', 'componente']
|
|
190
|
+
imagem_type = [ 'imagem', 'img', 'imagem_png', 'imagem_jpeg', 'image', 'imagem_exata', 'padrão_imagem', 'foto', 'captura_tela', 'screenshot', 'imagem_visual']
|
|
191
|
+
|
|
192
|
+
for escrita in text_type:
|
|
193
|
+
if escrita in type.lower():
|
|
194
|
+
type = "text"
|
|
195
|
+
|
|
196
|
+
for escrita in element_type:
|
|
197
|
+
if escrita in type.lower():
|
|
198
|
+
type = "element"
|
|
199
|
+
|
|
200
|
+
for escrita in imagem_type:
|
|
201
|
+
if escrita in type.lower():
|
|
202
|
+
type = "image"
|
|
203
|
+
|
|
204
|
+
return find_elements.backcode__dont_use__wait_for_d(driver, object, type, timeout=tempo)
|
|
205
|
+
|
|
206
|
+
def Select_element_func(element, method, key, relative = None):
|
|
207
|
+
"""
|
|
208
|
+
Selects an option in a <select> element.
|
|
209
|
+
|
|
210
|
+
Args:
|
|
211
|
+
element: The <select> element found by Selenium.
|
|
212
|
+
method: Selection method ('index', 'text', or 'value').
|
|
213
|
+
key: Value used for selection (index, visible text, or 'value' attribute).
|
|
214
|
+
|
|
215
|
+
Example:
|
|
216
|
+
select_element = SeleniumTwo.find_element_with_wait("xpath", '//select[@value="FIRST_SELECT_VALUE"]')
|
|
217
|
+
|
|
218
|
+
first_option = nr_select(select_element, "text", "FIRST SELECT TEXT")
|
|
219
|
+
first_option = nr_select(select_element, "value", "FIRST_SELECT_VALUE")
|
|
220
|
+
first_option = nr_select(select_element, "index", "0")
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
variations = {
|
|
224
|
+
'index': ['index', 'indice', 'índice', 'posição', 'posição_na_lista', 'opção_numero', 'número_da_opção', 'opcao_indice', 'indice_da_opcao', 'numero_de_entrada'],
|
|
225
|
+
'text': ['text', 'texto', 'texto_visível', 'conteúdo', 'frase', 'texto_exibido', 'palavra', 'mensagem', 'texto_na_página', 'texto_da_opcao'],
|
|
226
|
+
'value': ['value', 'valor', 'valor_opcao', 'valor_da_opcao', 'valor_selecionado', 'value_opcao', 'valor_item', 'opcao_valor', 'item_valor', 'valor_atributo']
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for key_method, values in variations.items():
|
|
230
|
+
if method.lower() in map(str.lower, values):
|
|
231
|
+
method = key_method
|
|
232
|
+
break
|
|
233
|
+
|
|
234
|
+
else:
|
|
235
|
+
raise ValueError(f"Método '{method}' não é válido. Escolha entre 'index', 'text' ou 'value'.")
|
|
236
|
+
|
|
237
|
+
select = Select(element)
|
|
238
|
+
if method == "value":
|
|
239
|
+
select.select_by_value(key)
|
|
240
|
+
|
|
241
|
+
if method == "text":
|
|
242
|
+
elements = select.options
|
|
243
|
+
for elm in elements:
|
|
244
|
+
if relative:
|
|
245
|
+
if key.lower().strip() in elm.text.lower().strip():
|
|
246
|
+
select.select_by_visible_text(elm.text)
|
|
247
|
+
return
|
|
248
|
+
else:
|
|
249
|
+
if key == elm.text:
|
|
250
|
+
select.select_by_visible_text(elm.text)
|
|
251
|
+
return
|
|
252
|
+
|
|
253
|
+
raise ModuleNotFoundError(f"Option {key} não encontrada")
|
|
254
|
+
|
|
255
|
+
if method == "index":
|
|
256
|
+
select.select_by_index(key)
|
|
257
|
+
|
|
258
|
+
def pop_up_extract(text: bool = False, accept: bool = False, timeout: int = 10, driver_instance: Optional[WebElement] = None):
|
|
259
|
+
""" Identifica um pop-up simples extraindo o texto e aceitando ele também. \n
|
|
260
|
+
|
|
261
|
+
- Como usar:
|
|
262
|
+
Chame a função e registrando ela em uma variável, and if you iniciate a driver without the library pass the driver variable.
|
|
263
|
+
|
|
264
|
+
- Exemplo:
|
|
265
|
+
text = nr.pop_up_extract(text:True, accept:True, timeout=5)
|
|
266
|
+
|
|
267
|
+
- OBS: Para uma espera infinit (até o elemento aparecer) coloque timeout = 0
|
|
268
|
+
"""
|
|
269
|
+
global driver
|
|
270
|
+
extract_text = None
|
|
271
|
+
|
|
272
|
+
if not driver_instance: driver_instance = driver
|
|
273
|
+
if timeout == 0:
|
|
274
|
+
timeout = float("inf")
|
|
275
|
+
|
|
276
|
+
attempts = 0
|
|
277
|
+
while attempts < timeout:
|
|
278
|
+
try:
|
|
279
|
+
jan = driver_instance.switch_to.alert
|
|
280
|
+
|
|
281
|
+
if text == True:
|
|
282
|
+
extract_text = jan.text
|
|
283
|
+
|
|
284
|
+
if accept == True:
|
|
285
|
+
jan.accept()
|
|
286
|
+
|
|
287
|
+
if extract_text:
|
|
288
|
+
return extract_text
|
|
289
|
+
return
|
|
290
|
+
|
|
291
|
+
except Exception as e:
|
|
292
|
+
last_exception = e
|
|
293
|
+
print(e)
|
|
294
|
+
attempts += 1
|
|
295
|
+
time.sleep(0.8)
|
|
296
|
+
|
|
297
|
+
raise ValueError("Pop-up não encontrado") from last_exception
|
|
298
|
+
|
|
299
|
+
def cpf_or_cnpj(numero: str) -> str:
|
|
300
|
+
"""
|
|
301
|
+
Identifica se um número é um CPF ou CNPJ.
|
|
302
|
+
|
|
303
|
+
- Retorna "CPF" se o número for um CPF válido.
|
|
304
|
+
- Retorna "CNPJ" se o número for um CNPJ válido.
|
|
305
|
+
- Retorna "Inválido" se não for nenhum dos dois.
|
|
306
|
+
"""
|
|
307
|
+
|
|
308
|
+
# Remove caracteres não numéricos (como pontos e traços)
|
|
309
|
+
numero = re.sub(r"\D", "", numero)
|
|
310
|
+
|
|
311
|
+
if len(numero) == 11:
|
|
312
|
+
return "CPF" if numero.isdigit() else "Inválido"
|
|
313
|
+
|
|
314
|
+
elif len(numero) == 14:
|
|
315
|
+
return "CNPJ" if numero.isdigit() else "Inválido"
|
|
316
|
+
|
|
317
|
+
return "Inválido"
|
|
318
|
+
|
|
319
|
+
janela = None
|
|
320
|
+
@staticmethod
|
|
321
|
+
def mostrar_mensagem(mensagem, tamanho_fonte=12, negrito=False, button: Optional[bool] = True):
|
|
322
|
+
global janela
|
|
323
|
+
|
|
324
|
+
try: fechar_janela(janela)
|
|
325
|
+
except: pass
|
|
326
|
+
|
|
327
|
+
root = tk.Tk()
|
|
328
|
+
root.withdraw()
|
|
329
|
+
|
|
330
|
+
janela = tk.Toplevel()
|
|
331
|
+
janela.title("Atenção!")
|
|
332
|
+
janela.configure(bg="white")
|
|
333
|
+
|
|
334
|
+
largura, altura = 400, 200
|
|
335
|
+
pos_x = (janela.winfo_screenwidth() - largura) // 2
|
|
336
|
+
pos_y = (janela.winfo_screenheight() - altura) // 2
|
|
337
|
+
janela.geometry(f"{largura}x{altura}+{pos_x}+{pos_y}")
|
|
338
|
+
janela.resizable(False, False)
|
|
339
|
+
janela.attributes("-topmost", True)
|
|
340
|
+
|
|
341
|
+
estilo_fonte = ("Helvetica", tamanho_fonte, "bold" if negrito else "normal")
|
|
342
|
+
|
|
343
|
+
label = tk.Label(janela, text=mensagem, bg="white", fg="black",
|
|
344
|
+
font=estilo_fonte, wraplength=380, justify="center")
|
|
345
|
+
label.pack(expand=True, padx=20, pady=20)
|
|
346
|
+
|
|
347
|
+
if isinstance(button, dict):
|
|
348
|
+
resultado = tk.IntVar()
|
|
349
|
+
|
|
350
|
+
def make_cmd(value):
|
|
351
|
+
return lambda: resultado.set(value)
|
|
352
|
+
|
|
353
|
+
frame_botoes = tk.Frame(janela, bg="white") # CRIAR O FRAME
|
|
354
|
+
frame_botoes.pack(pady=10) # EMPACOTAR O FRAME
|
|
355
|
+
|
|
356
|
+
for i, texto in enumerate(button.keys(), start=1):
|
|
357
|
+
tk.Button(frame_botoes, text=texto, command=make_cmd(i), width=10,
|
|
358
|
+
font=("Helvetica", 10)).pack(side="left", padx=5)
|
|
359
|
+
|
|
360
|
+
janela.grab_set()
|
|
361
|
+
janela.focus_set()
|
|
362
|
+
janela.wait_variable(resultado)
|
|
363
|
+
root.destroy()
|
|
364
|
+
return resultado.get()
|
|
365
|
+
|
|
366
|
+
else:
|
|
367
|
+
if button:
|
|
368
|
+
tk.Button(janela, text="OK", command=lambda: (janela.destroy(), root.destroy()),
|
|
369
|
+
width=10, font=("Helvetica", 10)).pack(pady=10)
|
|
370
|
+
|
|
371
|
+
janela.grab_set()
|
|
372
|
+
janela.focus_set()
|
|
373
|
+
if button:
|
|
374
|
+
janela.wait_window()
|
|
375
|
+
else:
|
|
376
|
+
root.mainloop()
|
|
377
|
+
return janela
|
|
378
|
+
|
|
379
|
+
def fechar_janela(janela_=None):
|
|
380
|
+
global janela
|
|
381
|
+
if janela_ == None: janela.destroy()
|
|
382
|
+
else: janela_.destroy()
|
|
383
|
+
|
|
384
|
+
def move_mouse_smoothly(element, click=False):
|
|
385
|
+
import pyautogui
|
|
386
|
+
cordenadas_botao_certificado = element.location
|
|
387
|
+
x = cordenadas_botao_certificado["x"]+140
|
|
388
|
+
y = cordenadas_botao_certificado["y"]+112
|
|
389
|
+
|
|
390
|
+
actual_position = pyautogui.position()
|
|
391
|
+
mouse_x = actual_position[0]
|
|
392
|
+
mouse_y = actual_position[1]
|
|
393
|
+
|
|
394
|
+
print(x, y)
|
|
395
|
+
while True:
|
|
396
|
+
distancia = math.sqrt((x - mouse_x) ** 2 + (y - mouse_y) ** 2)
|
|
397
|
+
|
|
398
|
+
# Se a distância for menor que 200 pixels, o movimento será mais lento
|
|
399
|
+
if distancia < 200:
|
|
400
|
+
if mouse_x < x: mouse_x += random.randint(1, 20)
|
|
401
|
+
elif mouse_x > x: mouse_x -= random.randint(1, 20)
|
|
402
|
+
|
|
403
|
+
if mouse_y < y: mouse_y += random.randint(1, 10)
|
|
404
|
+
elif mouse_y > y: mouse_y -= random.randint(1, 10)
|
|
405
|
+
|
|
406
|
+
pyautogui.moveTo(mouse_x, mouse_y, duration=(random.randint(10, 100) / 1000))
|
|
407
|
+
|
|
408
|
+
else:
|
|
409
|
+
# Quando a distância é maior, o movimento é mais rápido
|
|
410
|
+
if mouse_x < x: mouse_x += random.randint(10, 50)
|
|
411
|
+
elif mouse_x > x: mouse_x -= random.randint(10, 50)
|
|
412
|
+
|
|
413
|
+
if mouse_y < y: mouse_y += random.randint(5, 20)
|
|
414
|
+
elif mouse_y > y: mouse_y -= random.randint(5, 20)
|
|
415
|
+
|
|
416
|
+
pyautogui.moveTo(mouse_x, mouse_y, duration=(random.randint(50, 300) / 1000))
|
|
417
|
+
|
|
418
|
+
if distancia < 7:
|
|
419
|
+
if click == True: pyautogui.click()
|
|
420
|
+
break
|
|
421
|
+
|
|
422
|
+
RESET, GR, ORANGE, DK_ORANGE = "\033[0m", "\033[38;5;34m", "\033[38;5;214m", "\033[38;5;130m"
|
|
423
|
+
try:
|
|
424
|
+
result = subprocess.run(['pip', 'show', "SeleniumTwo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
425
|
+
version_line = next((line for line in result.stdout.decode().splitlines() if line.startswith('Version:')), None)
|
|
426
|
+
except:
|
|
427
|
+
pass
|
|
428
|
+
try: print(f"\n\n{ORANGE}SeleniumTwo imported - {re.sub(r"[^0-9.b]", "", version_line)}{RESET}")
|
|
429
|
+
except: pass
|
|
430
|
+
# create_dirs()
|