rpa-suite 1.3.4__py3-none-any.whl → 1.3.6__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.
- rpa_suite/__init__.py +4 -1
- rpa_suite/core/__init__.py +1 -0
- rpa_suite/core/clock.py +271 -0
- rpa_suite/core/date.py +138 -0
- rpa_suite/core/dir.py +182 -0
- rpa_suite/core/email.py +343 -0
- rpa_suite/core/file.py +209 -0
- rpa_suite/core/log.py +304 -0
- rpa_suite/core/print.py +197 -0
- rpa_suite/core/regex.py +62 -0
- rpa_suite/core/validate.py +220 -0
- rpa_suite/{log → functions}/__create_log_dir.py +5 -7
- rpa_suite/{file → functions}/__create_ss_dir.py +2 -2
- rpa_suite/functions/__init__.py +1 -0
- rpa_suite/{log → functions}/_functions_logger.py +8 -8
- rpa_suite/{log → functions}/_logger.py +3 -3
- rpa_suite/suite.py +238 -148
- {rpa_suite-1.3.4.dist-info → rpa_suite-1.3.6.dist-info}/METADATA +7 -4
- rpa_suite-1.3.6.dist-info/RECORD +25 -0
- rpa_suite/clock/__init__.py +0 -1
- rpa_suite/clock/exec_at.py +0 -133
- rpa_suite/clock/scheduler.py +0 -38
- rpa_suite/clock/waiter.py +0 -139
- rpa_suite/date/__init__.py +0 -1
- rpa_suite/date/date.py +0 -124
- rpa_suite/email/__init__.py +0 -1
- rpa_suite/email/sender_smtp.py +0 -203
- rpa_suite/file/__init__.py +0 -1
- rpa_suite/file/counter.py +0 -69
- rpa_suite/file/file_flag.py +0 -103
- rpa_suite/file/screen_shot.py +0 -91
- rpa_suite/file/temp_dir.py +0 -176
- rpa_suite/log/__init__.py +0 -1
- rpa_suite/log/functions_logger_uru.py +0 -172
- rpa_suite/log/log_decorator.py +0 -37
- rpa_suite/log/logger_uru.py +0 -110
- rpa_suite/regex/__init__.py +0 -1
- rpa_suite/regex/pattern_in_text.py +0 -58
- rpa_suite/validate/__init__.py +0 -1
- rpa_suite/validate/mail_validator.py +0 -93
- rpa_suite/validate/string_validator.py +0 -120
- rpa_suite-1.3.4.dist-info/RECORD +0 -36
- /rpa_suite/{log/printer.py → functions/_printer.py} +0 -0
- /rpa_suite/{log → functions}/_variables.py +0 -0
- /rpa_suite/{log → functions}/_variables_uru.py +0 -0
- {rpa_suite-1.3.4.dist-info → rpa_suite-1.3.6.dist-info}/WHEEL +0 -0
- {rpa_suite-1.3.4.dist-info → rpa_suite-1.3.6.dist-info}/licenses/LICENSE +0 -0
- {rpa_suite-1.3.4.dist-info → rpa_suite-1.3.6.dist-info}/top_level.txt +0 -0
rpa_suite/core/log.py
ADDED
@@ -0,0 +1,304 @@
|
|
1
|
+
from typing import Optional as Op
|
2
|
+
from ..functions.__create_log_dir import _create_log_dir
|
3
|
+
from rpa_suite.functions._printer import error_print, alert_print
|
4
|
+
from loguru import logger
|
5
|
+
import sys, os, inspect
|
6
|
+
|
7
|
+
|
8
|
+
class Filters():
|
9
|
+
word_filter: Op[list[str]]
|
10
|
+
|
11
|
+
def __call__(self, record):
|
12
|
+
|
13
|
+
if len(self.word_filter) > 0:
|
14
|
+
|
15
|
+
for words in self.word_filter:
|
16
|
+
|
17
|
+
string_words: list[str] = [str(word) for word in words]
|
18
|
+
|
19
|
+
for word in string_words:
|
20
|
+
if word in record["message"]:
|
21
|
+
record["message"] = 'Log Alterado devido a palavra Filtrada!'
|
22
|
+
return True
|
23
|
+
|
24
|
+
return True
|
25
|
+
|
26
|
+
|
27
|
+
class CustomHandler():
|
28
|
+
def __init__(self, formatter):
|
29
|
+
self.formatter = formatter
|
30
|
+
|
31
|
+
def write(self, message):
|
32
|
+
frame = inspect.currentframe().f_back.f_back
|
33
|
+
log_msg = self.formatter.format(message, frame)
|
34
|
+
sys.stderr.write(log_msg)
|
35
|
+
|
36
|
+
|
37
|
+
class CustomFormatter:
|
38
|
+
def format(self, record):
|
39
|
+
|
40
|
+
frame = inspect.currentframe().f_back
|
41
|
+
full_path_filename = frame.f_code.co_filename
|
42
|
+
|
43
|
+
# Obtenha o nome do arquivo e o nome da pasta
|
44
|
+
filename = os.path.basename(full_path_filename)
|
45
|
+
foldername = os.path.basename(os.path.dirname(full_path_filename))
|
46
|
+
|
47
|
+
# Combine o nome da pasta e o nome do arquivo
|
48
|
+
filename = os.path.join(foldername, filename)
|
49
|
+
lineno = frame.f_lineno
|
50
|
+
|
51
|
+
# Formate a mensagem de log TERMINAL
|
52
|
+
format_string = "<green>{time:DD.MM.YY.HH:mm}</green> <level>{level: <8}</level> <level>{message}</level>\n"
|
53
|
+
|
54
|
+
log_msg = format_string.format(
|
55
|
+
time=record["time"],
|
56
|
+
level=record["level"].name,
|
57
|
+
filename=filename,
|
58
|
+
lineno=lineno,
|
59
|
+
message=record["message"]
|
60
|
+
)
|
61
|
+
return log_msg
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
class Log():
|
67
|
+
|
68
|
+
filters: Filters
|
69
|
+
custom_handler: CustomHandler
|
70
|
+
custom_formatter: CustomFormatter
|
71
|
+
|
72
|
+
|
73
|
+
def __init__(self):
|
74
|
+
...
|
75
|
+
|
76
|
+
def config_logger(self,
|
77
|
+
path_dir:str = None,
|
78
|
+
name_log_dir:str = None,
|
79
|
+
name_file_log: str = 'log',
|
80
|
+
use_default_path_and_name: bool = True,
|
81
|
+
filter_words: list[str] = None):
|
82
|
+
|
83
|
+
"""
|
84
|
+
Function responsible for create a object logger with fileHandler and streamHandler
|
85
|
+
"""
|
86
|
+
|
87
|
+
try:
|
88
|
+
|
89
|
+
if not use_default_path_and_name:
|
90
|
+
result_tryed: dict = _create_log_dir(path_dir, name_log_dir)
|
91
|
+
path_dir = result_tryed['path_created']
|
92
|
+
else:
|
93
|
+
if path_dir == None and name_log_dir == None:
|
94
|
+
result_tryed: dict = _create_log_dir()
|
95
|
+
path_dir = result_tryed['path_created']
|
96
|
+
|
97
|
+
|
98
|
+
# ATRIBUIÇÕES
|
99
|
+
new_filter: Op[Filters] = None
|
100
|
+
if filter_words is not None:
|
101
|
+
new_filter: Filters = Filters()
|
102
|
+
new_filter.word_filter = [filter_words]
|
103
|
+
|
104
|
+
|
105
|
+
# configuração de objetos logger
|
106
|
+
file_handler = fr'{path_dir}\{name_file_log}.log'
|
107
|
+
logger.remove()
|
108
|
+
|
109
|
+
# Formate a mensagem de log FILE
|
110
|
+
log_format: str = "<green>{time:DD.MM.YY.HH:mm}</green> <level>{level: <8}</level> <green>{extra[filename]}</green>:{extra[lineno]: <4} <level>{message}</level>"
|
111
|
+
|
112
|
+
|
113
|
+
formatter = CustomFormatter()
|
114
|
+
if new_filter is not None:
|
115
|
+
logger.add(file_handler, filter=new_filter, level="DEBUG", format=log_format)
|
116
|
+
else:
|
117
|
+
logger.add(file_handler, level="DEBUG", format=log_format)
|
118
|
+
|
119
|
+
# Adicione sys.stderr como um manipulador
|
120
|
+
logger.add(sys.stderr, level="DEBUG", format=formatter.format)
|
121
|
+
|
122
|
+
return file_handler
|
123
|
+
|
124
|
+
except Exception as e:
|
125
|
+
|
126
|
+
error_print(f'Houve um erro durante a execução da função: {self.config_logger.__name__}! Error: {str(e)}.')
|
127
|
+
return None
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
def log_start_run_debug(self,
|
132
|
+
msg_start_loggin: str) -> None: # represent start application
|
133
|
+
|
134
|
+
"""
|
135
|
+
Function responsable to generate ``start run log level debug``, in file and print on terminal the same log captured on this call.
|
136
|
+
"""
|
137
|
+
|
138
|
+
file_h: False
|
139
|
+
|
140
|
+
try:
|
141
|
+
file_h = self.config_logger()
|
142
|
+
|
143
|
+
except Exception as e:
|
144
|
+
|
145
|
+
error_print(f'Para usar o log_start_run_debug é necessario instanciar file_handler usando o arquivo "logger_uru" em algum arquivo de configuração do seu projeto primeiramente! Error: {str(e)}')
|
146
|
+
|
147
|
+
try:
|
148
|
+
try:
|
149
|
+
if file_h:
|
150
|
+
with open(file_h, 'a') as f:
|
151
|
+
f.write('\n')
|
152
|
+
|
153
|
+
except Exception as e:
|
154
|
+
alert_print(f'Não foi possivel gerar break_row para log inicial!')
|
155
|
+
|
156
|
+
# logger.debug(f'{msg_start_loggin}')
|
157
|
+
frame = inspect.currentframe().f_back
|
158
|
+
full_path_filename = frame.f_code.co_filename
|
159
|
+
|
160
|
+
# Obtenha o nome do arquivo e o nome da pasta
|
161
|
+
filename = os.path.basename(full_path_filename)
|
162
|
+
foldername = os.path.basename(os.path.dirname(full_path_filename))
|
163
|
+
|
164
|
+
# Combine o nome da pasta e o nome do arquivo
|
165
|
+
filename = os.path.join(foldername, filename)
|
166
|
+
lineno = frame.f_lineno
|
167
|
+
|
168
|
+
# Vincule o nome do arquivo e a linha à mensagem de log
|
169
|
+
logger.bind(filename=filename, lineno=lineno).debug(f'{msg_start_loggin}')
|
170
|
+
|
171
|
+
except Exception as e:
|
172
|
+
error_print(f'Erro durante a função: {self.log_start_run_debug.__name__}! Error: {str(e)}')
|
173
|
+
|
174
|
+
|
175
|
+
def log_debug(
|
176
|
+
self,
|
177
|
+
msg: str) -> None:
|
178
|
+
|
179
|
+
"""
|
180
|
+
Function responsable to generate log level ``debug``, in file and print on terminal the same log captured on this call.
|
181
|
+
"""
|
182
|
+
|
183
|
+
try:
|
184
|
+
frame = inspect.currentframe().f_back
|
185
|
+
full_path_filename = frame.f_code.co_filename
|
186
|
+
|
187
|
+
# Obtenha o nome do arquivo e o nome da pasta
|
188
|
+
filename = os.path.basename(full_path_filename)
|
189
|
+
foldername = os.path.basename(os.path.dirname(full_path_filename))
|
190
|
+
|
191
|
+
# Combine o nome da pasta e o nome do arquivo
|
192
|
+
filename = os.path.join(foldername, filename)
|
193
|
+
lineno = frame.f_lineno
|
194
|
+
|
195
|
+
# Vincule o nome do arquivo e a linha à mensagem de log
|
196
|
+
logger.bind(filename=filename, lineno=lineno).debug(msg)
|
197
|
+
|
198
|
+
except Exception as e:
|
199
|
+
error_print(f'Erro durante a função: {self.log_debug.__name__}! Error: {str(e)}')
|
200
|
+
|
201
|
+
def log_info(
|
202
|
+
self,
|
203
|
+
msg: str) -> None:
|
204
|
+
|
205
|
+
"""
|
206
|
+
Function responsable to generate log level ``info``, in file and print on terminal the same log captured on this call.
|
207
|
+
"""
|
208
|
+
|
209
|
+
try:
|
210
|
+
frame = inspect.currentframe().f_back
|
211
|
+
full_path_filename = frame.f_code.co_filename
|
212
|
+
|
213
|
+
# Obtenha o nome do arquivo e o nome da pasta
|
214
|
+
filename = os.path.basename(full_path_filename)
|
215
|
+
foldername = os.path.basename(os.path.dirname(full_path_filename))
|
216
|
+
|
217
|
+
# Combine o nome da pasta e o nome do arquivo
|
218
|
+
filename = os.path.join(foldername, filename)
|
219
|
+
lineno = frame.f_lineno
|
220
|
+
|
221
|
+
# Vincule o nome do arquivo e a linha à mensagem de log
|
222
|
+
logger.bind(filename=filename, lineno=lineno).info(msg)
|
223
|
+
|
224
|
+
except Exception as e:
|
225
|
+
error_print(f'Erro durante a função: {self.log_info.__name__}! Error: {str(e)}')
|
226
|
+
|
227
|
+
def log_warning(self,
|
228
|
+
msg: str) -> None:
|
229
|
+
|
230
|
+
"""
|
231
|
+
Function responsable to generate log level ``warning``, in file and print on terminal the same log captured on this call.
|
232
|
+
"""
|
233
|
+
|
234
|
+
try:
|
235
|
+
frame = inspect.currentframe().f_back
|
236
|
+
full_path_filename = frame.f_code.co_filename
|
237
|
+
|
238
|
+
# Obtenha o nome do arquivo e o nome da pasta
|
239
|
+
filename = os.path.basename(full_path_filename)
|
240
|
+
foldername = os.path.basename(os.path.dirname(full_path_filename))
|
241
|
+
|
242
|
+
# Combine o nome da pasta e o nome do arquivo
|
243
|
+
filename = os.path.join(foldername, filename)
|
244
|
+
lineno = frame.f_lineno
|
245
|
+
|
246
|
+
# Vincule o nome do arquivo e a linha à mensagem de log
|
247
|
+
logger.bind(filename=filename, lineno=lineno).warning(msg)
|
248
|
+
|
249
|
+
except Exception as e:
|
250
|
+
error_print(f'Erro durante a função: {self.log_warning.__name__}! Error: {str(e)}')
|
251
|
+
|
252
|
+
|
253
|
+
def log_error(
|
254
|
+
self,
|
255
|
+
msg: str) -> None:
|
256
|
+
|
257
|
+
"""
|
258
|
+
Function responsable to generate log level ``error``, in file and print on terminal the same log captured on this call.
|
259
|
+
"""
|
260
|
+
|
261
|
+
try:
|
262
|
+
frame = inspect.currentframe().f_back
|
263
|
+
full_path_filename = frame.f_code.co_filename
|
264
|
+
|
265
|
+
# Obtenha o nome do arquivo e o nome da pasta
|
266
|
+
filename = os.path.basename(full_path_filename)
|
267
|
+
foldername = os.path.basename(os.path.dirname(full_path_filename))
|
268
|
+
|
269
|
+
# Combine o nome da pasta e o nome do arquivo
|
270
|
+
filename = os.path.join(foldername, filename)
|
271
|
+
lineno = frame.f_lineno
|
272
|
+
|
273
|
+
# Vincule o nome do arquivo e a linha à mensagem de log
|
274
|
+
logger.bind(filename=filename, lineno=lineno).error(msg)
|
275
|
+
|
276
|
+
except Exception as e:
|
277
|
+
error_print(f'Erro durante a função: {self.log_error.__name__}! Error: {str(e)}')
|
278
|
+
|
279
|
+
|
280
|
+
def log_critical(self,
|
281
|
+
msg: str) -> None:
|
282
|
+
|
283
|
+
"""
|
284
|
+
Function responsable to generate log level ``critical``, in file and print on terminal the same log captured on this call.
|
285
|
+
"""
|
286
|
+
|
287
|
+
try:
|
288
|
+
frame = inspect.currentframe().f_back
|
289
|
+
full_path_filename = frame.f_code.co_filename
|
290
|
+
|
291
|
+
# Obtenha o nome do arquivo e o nome da pasta
|
292
|
+
filename = os.path.basename(full_path_filename)
|
293
|
+
foldername = os.path.basename(os.path.dirname(full_path_filename))
|
294
|
+
|
295
|
+
# Combine o nome da pasta e o nome do arquivo
|
296
|
+
filename = os.path.join(foldername, filename)
|
297
|
+
lineno = frame.f_lineno
|
298
|
+
|
299
|
+
# Vincule o nome do arquivo e a linha à mensagem de log
|
300
|
+
logger.bind(filename=filename, lineno=lineno).critical(msg)
|
301
|
+
|
302
|
+
except Exception as e:
|
303
|
+
error_print(f'Erro durante a função: {self.log_critical.__name__}! Error: {str(e)}')
|
304
|
+
|
rpa_suite/core/print.py
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
|
2
|
+
# /printer.py
|
3
|
+
|
4
|
+
from colorama import Fore
|
5
|
+
|
6
|
+
# Windows bash colors
|
7
|
+
class Colors():
|
8
|
+
black = f'{Fore.BLACK}'
|
9
|
+
blue = f'{Fore.BLUE}'
|
10
|
+
green = f'{Fore.GREEN}'
|
11
|
+
cyan = f'{Fore.CYAN}'
|
12
|
+
red = f'{Fore.RED}'
|
13
|
+
magenta = f'{Fore.MAGENTA}'
|
14
|
+
yellow = f'{Fore.YELLOW}'
|
15
|
+
white = f'{Fore.WHITE}'
|
16
|
+
default = f'{Fore.WHITE}'
|
17
|
+
call_fn = f'{Fore.LIGHTMAGENTA_EX}'
|
18
|
+
retur_fn = f'{Fore.LIGHTYELLOW_EX}'
|
19
|
+
|
20
|
+
class Print():
|
21
|
+
|
22
|
+
colors: Colors = Colors
|
23
|
+
|
24
|
+
def __init__(self):
|
25
|
+
...
|
26
|
+
|
27
|
+
|
28
|
+
def success_print(self,
|
29
|
+
string_text: str,
|
30
|
+
color=Colors.green,
|
31
|
+
ending="\n") -> None:
|
32
|
+
"""
|
33
|
+
Print that indicates ``SUCCESS``. Customized with the color Green \n
|
34
|
+
|
35
|
+
Return:
|
36
|
+
----------
|
37
|
+
>>> type:None
|
38
|
+
|
39
|
+
pt-br
|
40
|
+
----------
|
41
|
+
Print que indica ``SUCESSO``. Personalizado com a cor Verde \n
|
42
|
+
|
43
|
+
Retorno:
|
44
|
+
----------
|
45
|
+
>>> type:None
|
46
|
+
"""
|
47
|
+
print(f'{color}{string_text}{Colors.default}', end=ending)
|
48
|
+
|
49
|
+
|
50
|
+
def alert_print(self,
|
51
|
+
string_text: str,
|
52
|
+
color=Colors.yellow,
|
53
|
+
ending="\n") -> None:
|
54
|
+
"""
|
55
|
+
Print that indicates ``ALERT``. Customized with the color Yellow \n
|
56
|
+
|
57
|
+
Return:
|
58
|
+
----------
|
59
|
+
>>> type:None
|
60
|
+
|
61
|
+
pt-br
|
62
|
+
----------
|
63
|
+
Print que indica ``ALERTA``. Personalizado com a cor Amarelo \n
|
64
|
+
Retorno:
|
65
|
+
----------
|
66
|
+
>>> type:None
|
67
|
+
"""
|
68
|
+
print(f'{color}{string_text}{Colors.default}', end=ending)
|
69
|
+
|
70
|
+
|
71
|
+
def info_print(self,
|
72
|
+
string_text: str,
|
73
|
+
color=Colors.cyan,
|
74
|
+
ending="\n") -> None:
|
75
|
+
"""
|
76
|
+
Print that indicates ``INFORMATION``. Customized with the color Cyan \n
|
77
|
+
|
78
|
+
Return:
|
79
|
+
----------
|
80
|
+
>>> type:None
|
81
|
+
|
82
|
+
pt-br
|
83
|
+
----------
|
84
|
+
Print que indica ``INFORMATIVO``. Personalizado com a cor Ciano \n
|
85
|
+
Retorno:
|
86
|
+
----------
|
87
|
+
>>> type:None
|
88
|
+
"""
|
89
|
+
print(f'{color}{string_text}{Colors.default}', end=ending)
|
90
|
+
|
91
|
+
|
92
|
+
def error_print(self,
|
93
|
+
string_text: str,
|
94
|
+
color=Colors.red,
|
95
|
+
ending="\n") -> None:
|
96
|
+
"""
|
97
|
+
Print that indicates ``ERROR``. Customized with the color Red \n
|
98
|
+
|
99
|
+
Return:
|
100
|
+
----------
|
101
|
+
>>> type:None
|
102
|
+
|
103
|
+
pt-br
|
104
|
+
----------
|
105
|
+
Print que indica ``ERRO``. Personalizado com a cor Vermelho \n
|
106
|
+
Retorno:
|
107
|
+
----------
|
108
|
+
>>> type:None
|
109
|
+
"""
|
110
|
+
print(f'{color}{string_text}{Colors.default}', end=ending)
|
111
|
+
|
112
|
+
|
113
|
+
def magenta_print(self,
|
114
|
+
string_text: str,
|
115
|
+
color=Colors.magenta,
|
116
|
+
ending="\n") -> None:
|
117
|
+
"""
|
118
|
+
Print customized with the color Magenta \n
|
119
|
+
|
120
|
+
Return:
|
121
|
+
----------
|
122
|
+
>>> type:None
|
123
|
+
|
124
|
+
pt-br
|
125
|
+
----------
|
126
|
+
Print personalizado com a cor Magenta \n
|
127
|
+
Retorno:
|
128
|
+
----------
|
129
|
+
>>> type:None
|
130
|
+
"""
|
131
|
+
print(f'{color}{string_text}{Colors.default}', end=ending)
|
132
|
+
|
133
|
+
|
134
|
+
def blue_print(self,
|
135
|
+
string_text: str,
|
136
|
+
color=Colors.blue,
|
137
|
+
ending="\n") -> None:
|
138
|
+
"""
|
139
|
+
Print customized with the color Blue \n
|
140
|
+
|
141
|
+
Return:
|
142
|
+
----------
|
143
|
+
>>> type:None
|
144
|
+
|
145
|
+
pt-br
|
146
|
+
----------
|
147
|
+
Print personalizado com a cor Azul \n
|
148
|
+
Retorno:
|
149
|
+
----------
|
150
|
+
>>> type:None
|
151
|
+
"""
|
152
|
+
print(f'{color}{string_text}{Colors.default}', end=ending)
|
153
|
+
|
154
|
+
|
155
|
+
def print_call_fn(self,
|
156
|
+
string_text: str,
|
157
|
+
color=Colors.call_fn,
|
158
|
+
ending="\n") -> None:
|
159
|
+
"""
|
160
|
+
Print customized for function called (log) \n
|
161
|
+
Color: Magenta Light
|
162
|
+
Return:
|
163
|
+
----------
|
164
|
+
>>> type:None
|
165
|
+
|
166
|
+
pt-br
|
167
|
+
----------
|
168
|
+
Print personalizado para log de chamada de função. \n
|
169
|
+
Cor: Magenta Light
|
170
|
+
Retorno:
|
171
|
+
----------
|
172
|
+
>>> type:None
|
173
|
+
"""
|
174
|
+
print(f'{color}{string_text}{Colors.default}', end=ending)
|
175
|
+
|
176
|
+
|
177
|
+
def print_retur_fn(self,
|
178
|
+
string_text: str,
|
179
|
+
color=Colors.retur_fn,
|
180
|
+
ending="\n") -> None:
|
181
|
+
"""
|
182
|
+
Print customized for function return (log) \n
|
183
|
+
Color: Yellow Light
|
184
|
+
Return:
|
185
|
+
----------
|
186
|
+
>>> type:None
|
187
|
+
|
188
|
+
pt-br
|
189
|
+
----------
|
190
|
+
Print personalizado para log de chamada de função. \n
|
191
|
+
Cor: Yellow Light
|
192
|
+
Retorno:
|
193
|
+
----------
|
194
|
+
>>> type:None
|
195
|
+
"""
|
196
|
+
print(f'{color}{string_text}{Colors.default}', end=ending)
|
197
|
+
|
rpa_suite/core/regex.py
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
import re
|
3
|
+
from rpa_suite.functions._printer import error_print, success_print
|
4
|
+
|
5
|
+
class Regex():
|
6
|
+
|
7
|
+
def __init__(self):
|
8
|
+
...
|
9
|
+
|
10
|
+
def check_pattern_in_text(self,
|
11
|
+
origin_text: str,
|
12
|
+
pattern_to_search: str,
|
13
|
+
case_sensitive: bool = True,
|
14
|
+
display_message: bool = False) -> bool:
|
15
|
+
|
16
|
+
"""
|
17
|
+
Function responsible for searching in a string ``origin_text`` a pattern ``pattern_to_search`` and returning True if the pattern is found, otherwise False. ``case_sensitive`` used for exact cases or cases with diferencce upper and lower cases
|
18
|
+
|
19
|
+
Return:
|
20
|
+
----------
|
21
|
+
A boolean indicating whether the pattern was found in the text.
|
22
|
+
|
23
|
+
Description: pt-br
|
24
|
+
----------
|
25
|
+
Função responsável por buscar em um texto de leitura humana uma string ``origin_text`` por um padrão ``pattern_to_search`` e retornar True se o padrão for encontrado, caso contrário, False. ``case_sensitive`` usado para casos exatos ou casos com diferença entre caixa alta e baixa nos caracteres.
|
26
|
+
|
27
|
+
Retorno:
|
28
|
+
----------
|
29
|
+
Um booleano indicando se o padrão foi encontrado no texto.
|
30
|
+
"""
|
31
|
+
|
32
|
+
try:
|
33
|
+
|
34
|
+
if case_sensitive:
|
35
|
+
|
36
|
+
# Check if the pattern is found in the text
|
37
|
+
if re.search(pattern_to_search, origin_text):
|
38
|
+
if display_message: success_print(f'Pattern found successfully!')
|
39
|
+
return True
|
40
|
+
|
41
|
+
else:
|
42
|
+
if display_message: success_print(f'Pattern not found.')
|
43
|
+
return False
|
44
|
+
else:
|
45
|
+
|
46
|
+
# normalize text to search without case sensitive
|
47
|
+
origin_text = origin_text.lower()
|
48
|
+
pattern_to_search = pattern_to_search.lower()
|
49
|
+
|
50
|
+
# Check if the pattern is found in the text
|
51
|
+
if re.search(pattern_to_search, origin_text):
|
52
|
+
if display_message: success_print(f'Pattern found successfully!')
|
53
|
+
return True
|
54
|
+
|
55
|
+
else:
|
56
|
+
if display_message: success_print(f'Pattern not found.')
|
57
|
+
return False
|
58
|
+
|
59
|
+
except Exception as e:
|
60
|
+
|
61
|
+
error_print(f"Error function: {self.check_pattern_in_text.__name__} when trying to check pattern in text. Error: {str(e)}")
|
62
|
+
return False
|