rpa-suite 1.5.3__py3-none-any.whl → 1.5.4__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 +57 -56
- rpa_suite/core/__init__.py +3 -2
- rpa_suite/core/asyncrun.py +31 -33
- rpa_suite/core/browser.py +110 -81
- rpa_suite/core/clock.py +115 -118
- rpa_suite/core/date.py +36 -40
- rpa_suite/core/dir.py +66 -56
- rpa_suite/core/email.py +55 -53
- rpa_suite/core/file.py +88 -76
- rpa_suite/core/log.py +26 -10
- rpa_suite/core/parallel.py +106 -96
- rpa_suite/core/print.py +42 -70
- rpa_suite/core/regex.py +29 -22
- rpa_suite/core/validate.py +89 -86
- rpa_suite/functions/__create_ss_dir.py +24 -20
- rpa_suite/functions/__init__.py +1 -1
- rpa_suite/functions/_printer.py +20 -20
- rpa_suite/suite.py +71 -101
- rpa_suite/utils/system.py +7 -5
- {rpa_suite-1.5.3.dist-info → rpa_suite-1.5.4.dist-info}/METADATA +75 -58
- rpa_suite-1.5.4.dist-info/RECORD +25 -0
- rpa_suite-1.5.3.dist-info/RECORD +0 -25
- {rpa_suite-1.5.3.dist-info → rpa_suite-1.5.4.dist-info}/WHEEL +0 -0
- {rpa_suite-1.5.3.dist-info → rpa_suite-1.5.4.dist-info}/licenses/LICENSE +0 -0
- {rpa_suite-1.5.3.dist-info → rpa_suite-1.5.4.dist-info}/top_level.txt +0 -0
rpa_suite/core/file.py
CHANGED
@@ -13,7 +13,7 @@ from datetime import datetime
|
|
13
13
|
from typing import Dict, List, Union
|
14
14
|
|
15
15
|
|
16
|
-
class File
|
16
|
+
class File:
|
17
17
|
"""
|
18
18
|
Class that provides utilities for file management, including creation, deletion, and manipulation of files.
|
19
19
|
|
@@ -63,19 +63,20 @@ class File():
|
|
63
63
|
save_with_date (bool): Indica se o nome do arquivo deve incluir a data
|
64
64
|
delay (int): O tempo de espera antes de capturar a tela
|
65
65
|
"""
|
66
|
-
|
66
|
+
|
67
67
|
def __init__(self):
|
68
68
|
self.__create_ss_dir = create_ss_dir
|
69
69
|
|
70
|
-
def screen_shot(
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
70
|
+
def screen_shot(
|
71
|
+
self,
|
72
|
+
file_name: str = "screenshot",
|
73
|
+
path_dir: str = None,
|
74
|
+
save_with_date: bool = True,
|
75
|
+
delay: int = 1,
|
76
|
+
use_default_path_and_name: bool = True,
|
77
|
+
name_ss_dir: str | None = None,
|
78
|
+
display_message: bool = False,
|
79
|
+
) -> str | None:
|
79
80
|
"""
|
80
81
|
Function responsible for create a dir for screenshot, and file screenshot and save this in dir to create, if dir exists save it on original dir. By default uses date on file name. \n
|
81
82
|
|
@@ -107,7 +108,7 @@ class File():
|
|
107
108
|
``use_default_path_and_name: bool`` - deve ser um booleano, por padrão `True`
|
108
109
|
``name_ss_dir: str`` - deve ser uma string, por padrão do tipo `None`
|
109
110
|
``display_message`` - deve ser um booleano, por padrão `False`
|
110
|
-
|
111
|
+
|
111
112
|
Retorno:
|
112
113
|
----------
|
113
114
|
>>> tipo: str
|
@@ -116,107 +117,118 @@ class File():
|
|
116
117
|
|
117
118
|
# proccess
|
118
119
|
try:
|
119
|
-
|
120
|
+
|
120
121
|
try:
|
121
122
|
import pyautogui
|
122
123
|
import pyscreeze
|
123
|
-
|
124
|
+
|
124
125
|
except ImportError:
|
125
|
-
raise ImportError(
|
126
|
-
|
126
|
+
raise ImportError(
|
127
|
+
f"\nThe 'pyautogui' e 'Pillow' libraries are necessary to use this module. {Fore.YELLOW}Please install them with: 'pip install pyautogui pillow'{Fore.WHITE}"
|
128
|
+
)
|
129
|
+
|
127
130
|
time.sleep(delay)
|
128
131
|
|
129
132
|
if not use_default_path_and_name:
|
130
133
|
result_tryed: dict = self.__create_ss_dir(path_dir, name_ss_dir)
|
131
|
-
path_dir = result_tryed[
|
134
|
+
path_dir = result_tryed["path_created"]
|
132
135
|
else:
|
133
136
|
result_tryed: dict = self.__create_ss_dir()
|
134
|
-
path_dir = result_tryed[
|
137
|
+
path_dir = result_tryed["path_created"]
|
135
138
|
|
136
|
-
|
137
|
-
if save_with_date: # use date on file name
|
139
|
+
if save_with_date: # use date on file name
|
138
140
|
image = pyautogui.screenshot()
|
139
|
-
file_name =
|
141
|
+
file_name = (
|
142
|
+
f'{file_name}_{datetime.today().strftime("%d_%m_%Y-%H_%M_%S")}.png'
|
143
|
+
)
|
140
144
|
path_file_screenshoted = os.path.join(path_dir, file_name)
|
141
|
-
|
145
|
+
|
142
146
|
image.save(path_file_screenshoted)
|
143
|
-
|
144
|
-
if display_message:
|
145
|
-
|
147
|
+
|
148
|
+
if display_message:
|
149
|
+
success_print(path_file_screenshoted)
|
150
|
+
|
146
151
|
return path_file_screenshoted
|
147
|
-
|
148
|
-
else:
|
152
|
+
|
153
|
+
else: # not use date on file name
|
149
154
|
image = pyautogui.screenshot()
|
150
|
-
file_name = f
|
155
|
+
file_name = f"{file_name}.png"
|
151
156
|
path_file_screenshoted = os.path.join(path_dir, file_name)
|
152
|
-
|
157
|
+
|
153
158
|
image.save(path_file_screenshoted)
|
154
|
-
|
155
|
-
if display_message:
|
156
|
-
|
159
|
+
|
160
|
+
if display_message:
|
161
|
+
success_print(path_file_screenshoted)
|
162
|
+
|
157
163
|
return path_file_screenshoted
|
158
|
-
|
164
|
+
|
159
165
|
except Exception as e:
|
160
166
|
|
161
|
-
error_print(
|
167
|
+
error_print(
|
168
|
+
f"Error to execute function:{self.screen_shot.__name__}! Error: {str(e)}"
|
169
|
+
)
|
162
170
|
return None
|
163
171
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
172
|
+
def flag_create(
|
173
|
+
self,
|
174
|
+
name_file: str = "running.flag",
|
175
|
+
path_to_create: str | None = None,
|
176
|
+
display_message: bool = True,
|
177
|
+
) -> None:
|
169
178
|
"""
|
170
179
|
Cria um arquivo de sinalização indicando que o robô está em execução.
|
171
180
|
"""
|
172
|
-
|
181
|
+
|
173
182
|
try:
|
174
183
|
if path_to_create == None:
|
175
184
|
path_origin: str = os.getcwd()
|
176
|
-
full_path_with_name =
|
185
|
+
full_path_with_name = rf"{path_origin}/{name_file}"
|
177
186
|
else:
|
178
|
-
full_path_with_name =
|
179
|
-
|
180
|
-
with open(full_path_with_name, 'w', encoding='utf-8') as file:
|
181
|
-
file.write('[RPA Suite] - Running Flag File')
|
182
|
-
if display_message: success_print("Flag file created.")
|
183
|
-
|
184
|
-
except Exception as e:
|
185
|
-
error_print(f'Erro na função file_scheduling_create: {str(e)}')
|
187
|
+
full_path_with_name = rf"{path_to_create}/{name_file}"
|
186
188
|
|
189
|
+
with open(full_path_with_name, "w", encoding="utf-8") as file:
|
190
|
+
file.write("[RPA Suite] - Running Flag File")
|
191
|
+
if display_message:
|
192
|
+
success_print("Flag file created.")
|
187
193
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
194
|
+
except Exception as e:
|
195
|
+
error_print(f"Erro na função file_scheduling_create: {str(e)}")
|
196
|
+
|
197
|
+
def flag_delete(
|
198
|
+
self,
|
199
|
+
name_file: str = "running.flag",
|
200
|
+
path_to_delete: str | None = None,
|
201
|
+
display_message: bool = True,
|
202
|
+
) -> None:
|
193
203
|
"""
|
194
204
|
Deleta o arquivo de sinalização indicando que o robô terminou a execução.
|
195
205
|
"""
|
196
|
-
|
206
|
+
|
197
207
|
try:
|
198
208
|
|
199
209
|
if path_to_delete == None:
|
200
210
|
path_origin: str = os.getcwd()
|
201
|
-
full_path_with_name =
|
211
|
+
full_path_with_name = rf"{path_origin}/{name_file}"
|
202
212
|
else:
|
203
|
-
full_path_with_name =
|
204
|
-
|
213
|
+
full_path_with_name = rf"{path_to_delete}/{name_file}"
|
214
|
+
|
205
215
|
if os.path.exists(full_path_with_name):
|
206
216
|
os.remove(full_path_with_name)
|
207
|
-
if display_message:
|
217
|
+
if display_message:
|
218
|
+
success_print("Flag file deleted.")
|
208
219
|
else:
|
209
220
|
alert_print("Flag file not found.")
|
210
221
|
|
211
222
|
except Exception as e:
|
212
|
-
error_print(f
|
223
|
+
error_print(f"Erro na função file_scheduling_delete: {str(e)}")
|
213
224
|
time.sleep(1)
|
214
225
|
|
215
|
-
def count_files(
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
226
|
+
def count_files(
|
227
|
+
self,
|
228
|
+
dir_to_count: List[str] = ["."],
|
229
|
+
type_extension: str = "*",
|
230
|
+
display_message: bool = False,
|
231
|
+
) -> Dict[str, Union[bool, int]]:
|
220
232
|
"""
|
221
233
|
Function responsible for counting files within a folder, considers subfolders to do the count, searches by file type, being all files by default. \n
|
222
234
|
|
@@ -248,25 +260,25 @@ class File():
|
|
248
260
|
"""
|
249
261
|
|
250
262
|
# Local Variables
|
251
|
-
result: dict = {
|
252
|
-
'success': False,
|
253
|
-
'qt': 0
|
254
|
-
}
|
263
|
+
result: dict = {"success": False, "qt": 0}
|
255
264
|
|
256
265
|
# Process
|
257
266
|
try:
|
258
267
|
for dir in dir_to_count:
|
259
268
|
for _, _, files in os.walk(dir):
|
260
269
|
for file in files:
|
261
|
-
if type_extension ==
|
262
|
-
result[
|
263
|
-
result[
|
264
|
-
|
265
|
-
if display_message:
|
270
|
+
if type_extension == "*" or file.endswith(f".{type_extension}"):
|
271
|
+
result["qt"] += 1
|
272
|
+
result["success"] = True
|
273
|
+
|
274
|
+
if display_message:
|
275
|
+
success_print(
|
276
|
+
f'Function: {self.count_files.__name__} counted {result["qt"]} files.'
|
277
|
+
)
|
266
278
|
|
267
279
|
except Exception as e:
|
268
|
-
result[
|
269
|
-
error_print(f
|
280
|
+
result["success"] = False
|
281
|
+
error_print(f"Error when trying to count files! Error: {str(e)}")
|
270
282
|
|
271
283
|
finally:
|
272
284
|
return result
|
rpa_suite/core/log.py
CHANGED
@@ -20,7 +20,7 @@ class Filters:
|
|
20
20
|
string_words: list[str] = [str(word) for word in words]
|
21
21
|
for word in string_words:
|
22
22
|
if word in record["message"]:
|
23
|
-
record["message"] =
|
23
|
+
record["message"] = "Log Alterado devido a palavra Filtrada!"
|
24
24
|
return True
|
25
25
|
return True
|
26
26
|
|
@@ -49,7 +49,7 @@ class CustomFormatter:
|
|
49
49
|
level=record["level"].name,
|
50
50
|
filename=filename,
|
51
51
|
lineno=lineno,
|
52
|
-
message=record["message"]
|
52
|
+
message=record["message"],
|
53
53
|
)
|
54
54
|
return log_msg
|
55
55
|
|
@@ -66,12 +66,18 @@ class Log:
|
|
66
66
|
def __init__(self):
|
67
67
|
self.logger = logger
|
68
68
|
|
69
|
-
def config_logger(
|
69
|
+
def config_logger(
|
70
|
+
self,
|
71
|
+
path_dir: str = "default",
|
72
|
+
name_log_dir: str = "Logs",
|
73
|
+
name_file_log: str = "log",
|
74
|
+
filter_words: list[str] = None,
|
75
|
+
):
|
70
76
|
try:
|
71
77
|
self.path_dir = path_dir
|
72
78
|
self.name_file_log = name_file_log
|
73
79
|
|
74
|
-
if self.path_dir ==
|
80
|
+
if self.path_dir == "default":
|
75
81
|
self.path_dir = os.getcwd()
|
76
82
|
|
77
83
|
full_path = os.path.join(self.path_dir, name_log_dir)
|
@@ -83,7 +89,9 @@ class Log:
|
|
83
89
|
except FileExistsError:
|
84
90
|
alert_print(f"Diretório:'{self.full_path}' já existe.")
|
85
91
|
except PermissionError:
|
86
|
-
alert_print(
|
92
|
+
alert_print(
|
93
|
+
f"Permissão negada: não é possível criar o diretório '{self.full_path}'."
|
94
|
+
)
|
87
95
|
|
88
96
|
new_filter = None
|
89
97
|
if filter_words is not None:
|
@@ -98,7 +106,9 @@ class Log:
|
|
98
106
|
formatter = CustomFormatter()
|
99
107
|
|
100
108
|
if new_filter:
|
101
|
-
self.logger.add(
|
109
|
+
self.logger.add(
|
110
|
+
file_handler, filter=new_filter, level="DEBUG", format=log_format
|
111
|
+
)
|
102
112
|
else:
|
103
113
|
self.logger.add(file_handler, level="DEBUG", format=log_format)
|
104
114
|
|
@@ -107,7 +117,9 @@ class Log:
|
|
107
117
|
return file_handler
|
108
118
|
|
109
119
|
except Exception as e:
|
110
|
-
error_print(
|
120
|
+
error_print(
|
121
|
+
f"Houve um erro durante a execução da função: {self.config_logger.__name__}! Error: {str(e)}."
|
122
|
+
)
|
111
123
|
return None
|
112
124
|
|
113
125
|
def _log(self, level: str, msg: str):
|
@@ -120,15 +132,19 @@ class Log:
|
|
120
132
|
lineno = frame.f_lineno
|
121
133
|
self.logger.bind(filename=filename, lineno=lineno).log(level, msg)
|
122
134
|
except Exception as e:
|
123
|
-
error_print(f
|
135
|
+
error_print(f"Erro durante a função de log! Error: {str(e)}")
|
124
136
|
|
125
137
|
def log_start_run_debug(self, msg_start_loggin: str) -> None:
|
126
138
|
try:
|
127
139
|
with open(self.file_handler, "a") as log_file:
|
128
|
-
log_file.write(
|
140
|
+
log_file.write(
|
141
|
+
"\n"
|
142
|
+
) # Add a blank line before logging the start message
|
129
143
|
self._log("DEBUG", msg_start_loggin)
|
130
144
|
except Exception as e:
|
131
|
-
error_print(
|
145
|
+
error_print(
|
146
|
+
f"Erro fn: {self.log_start_run_debug.__name__} ao tentar acessar o arquivo de log Confira se foi criado a configuração de log correta com a função config_logger e se a pasta e arquivo estão nos diretório desejado! Error: {str(e)}."
|
147
|
+
)
|
132
148
|
|
133
149
|
def log_debug(self, msg: str) -> None:
|
134
150
|
self._log("DEBUG", msg)
|