rpa-suite 1.3.4__tar.gz → 1.3.5__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.
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/PKG-INFO +7 -4
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/README.md +1 -1
- rpa_suite-1.3.5/rpa_suite/__init__.py +4 -0
- rpa_suite-1.3.5/rpa_suite/core/__init__.py +1 -0
- rpa_suite-1.3.5/rpa_suite/core/clock.py +271 -0
- rpa_suite-1.3.5/rpa_suite/core/date.py +138 -0
- rpa_suite-1.3.5/rpa_suite/core/dir.py +182 -0
- rpa_suite-1.3.5/rpa_suite/core/email.py +343 -0
- rpa_suite-1.3.5/rpa_suite/core/file.py +209 -0
- rpa_suite-1.3.5/rpa_suite/core/log.py +304 -0
- rpa_suite-1.3.5/rpa_suite/core/print.py +197 -0
- rpa_suite-1.3.5/rpa_suite/core/regex.py +62 -0
- rpa_suite-1.3.5/rpa_suite/core/validate.py +220 -0
- {rpa_suite-1.3.4/rpa_suite/log → rpa_suite-1.3.5/rpa_suite/functions}/__create_log_dir.py +5 -7
- {rpa_suite-1.3.4/rpa_suite/file → rpa_suite-1.3.5/rpa_suite/functions}/__create_ss_dir.py +2 -2
- rpa_suite-1.3.5/rpa_suite/functions/__init__.py +1 -0
- {rpa_suite-1.3.4/rpa_suite/log → rpa_suite-1.3.5/rpa_suite/functions}/_functions_logger.py +8 -8
- {rpa_suite-1.3.4/rpa_suite/log → rpa_suite-1.3.5/rpa_suite/functions}/_logger.py +3 -3
- rpa_suite-1.3.5/rpa_suite/suite.py +239 -0
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/rpa_suite.egg-info/PKG-INFO +7 -4
- rpa_suite-1.3.5/rpa_suite.egg-info/SOURCES.txt +28 -0
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/rpa_suite.egg-info/requires.txt +5 -2
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/setup.py +2 -2
- rpa_suite-1.3.4/rpa_suite/__init__.py +0 -1
- rpa_suite-1.3.4/rpa_suite/clock/__init__.py +0 -1
- rpa_suite-1.3.4/rpa_suite/clock/exec_at.py +0 -133
- rpa_suite-1.3.4/rpa_suite/clock/scheduler.py +0 -38
- rpa_suite-1.3.4/rpa_suite/clock/waiter.py +0 -139
- rpa_suite-1.3.4/rpa_suite/date/__init__.py +0 -1
- rpa_suite-1.3.4/rpa_suite/date/date.py +0 -124
- rpa_suite-1.3.4/rpa_suite/email/__init__.py +0 -1
- rpa_suite-1.3.4/rpa_suite/email/sender_smtp.py +0 -203
- rpa_suite-1.3.4/rpa_suite/file/__init__.py +0 -1
- rpa_suite-1.3.4/rpa_suite/file/counter.py +0 -69
- rpa_suite-1.3.4/rpa_suite/file/file_flag.py +0 -103
- rpa_suite-1.3.4/rpa_suite/file/screen_shot.py +0 -91
- rpa_suite-1.3.4/rpa_suite/file/temp_dir.py +0 -176
- rpa_suite-1.3.4/rpa_suite/log/__init__.py +0 -1
- rpa_suite-1.3.4/rpa_suite/log/functions_logger_uru.py +0 -172
- rpa_suite-1.3.4/rpa_suite/log/log_decorator.py +0 -37
- rpa_suite-1.3.4/rpa_suite/log/logger_uru.py +0 -110
- rpa_suite-1.3.4/rpa_suite/regex/__init__.py +0 -1
- rpa_suite-1.3.4/rpa_suite/regex/pattern_in_text.py +0 -58
- rpa_suite-1.3.4/rpa_suite/suite.py +0 -149
- rpa_suite-1.3.4/rpa_suite/validate/__init__.py +0 -1
- rpa_suite-1.3.4/rpa_suite/validate/mail_validator.py +0 -93
- rpa_suite-1.3.4/rpa_suite/validate/string_validator.py +0 -120
- rpa_suite-1.3.4/rpa_suite.egg-info/SOURCES.txt +0 -39
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/LICENSE +0 -0
- /rpa_suite-1.3.4/rpa_suite/log/printer.py → /rpa_suite-1.3.5/rpa_suite/functions/_printer.py +0 -0
- {rpa_suite-1.3.4/rpa_suite/log → rpa_suite-1.3.5/rpa_suite/functions}/_variables.py +0 -0
- {rpa_suite-1.3.4/rpa_suite/log → rpa_suite-1.3.5/rpa_suite/functions}/_variables_uru.py +0 -0
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/rpa_suite.egg-info/dependency_links.txt +0 -0
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/rpa_suite.egg-info/top_level.txt +0 -0
- {rpa_suite-1.3.4 → rpa_suite-1.3.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: rpa_suite
|
3
|
-
Version: 1.3.
|
3
|
+
Version: 1.3.5
|
4
4
|
Summary: Conjunto de ferramentas essenciais para Automação RPA com Python, que facilitam o dia a dia de desenvolvimento.
|
5
5
|
Author: Camilo Costa de Carvalho
|
6
6
|
Author-email: camilo.carvalho@triasoftware.com.br
|
@@ -18,10 +18,13 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
18
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
19
19
|
Description-Content-Type: text/markdown
|
20
20
|
License-File: LICENSE
|
21
|
-
Requires-Dist: loguru
|
22
21
|
Requires-Dist: colorama
|
23
|
-
Requires-Dist: email_validator
|
24
22
|
Requires-Dist: colorlog
|
23
|
+
Requires-Dist: email_validator
|
24
|
+
Requires-Dist: loguru
|
25
|
+
Requires-Dist: typing
|
26
|
+
Requires-Dist: pillow
|
27
|
+
Requires-Dist: openCV
|
25
28
|
Dynamic: author
|
26
29
|
Dynamic: author-email
|
27
30
|
Dynamic: classifier
|
@@ -183,7 +186,7 @@ Lançamento: *20/02/2024*
|
|
183
186
|
|
184
187
|
Status: Em desenvolvimento.
|
185
188
|
|
186
|
-
### Notas da atualização: 1.3.
|
189
|
+
### Notas da atualização: 1.3.5
|
187
190
|
|
188
191
|
- Correções de bugs em diversas funções relacionadas a tempo: *exec_at_hour* , *wait_for_exec* , *exec_and_wait*
|
189
192
|
- Correções de bugs com tempo superior a 10 minutos nas funções de data: *get_hms* e *get_dma*
|
@@ -148,7 +148,7 @@ Lançamento: *20/02/2024*
|
|
148
148
|
|
149
149
|
Status: Em desenvolvimento.
|
150
150
|
|
151
|
-
### Notas da atualização: 1.3.
|
151
|
+
### Notas da atualização: 1.3.5
|
152
152
|
|
153
153
|
- Correções de bugs em diversas funções relacionadas a tempo: *exec_at_hour* , *wait_for_exec* , *exec_and_wait*
|
154
154
|
- Correções de bugs com tempo superior a 10 minutos nas funções de data: *get_hms* e *get_dma*
|
@@ -0,0 +1 @@
|
|
1
|
+
# rpa_suite/core/__init__.py
|
@@ -0,0 +1,271 @@
|
|
1
|
+
|
2
|
+
import time
|
3
|
+
from typing import Callable, Any
|
4
|
+
from datetime import datetime as dt
|
5
|
+
from rpa_suite.functions._printer import error_print, success_print
|
6
|
+
from typing import Callable, Any
|
7
|
+
|
8
|
+
|
9
|
+
class Clock():
|
10
|
+
|
11
|
+
def __init__(self):
|
12
|
+
...
|
13
|
+
|
14
|
+
def exec_at_hour(self,
|
15
|
+
hour_to_exec: str,
|
16
|
+
fn_to_exec: Callable[..., Any],
|
17
|
+
*args,
|
18
|
+
**kwargs,
|
19
|
+
) -> dict[str, bool]:
|
20
|
+
|
21
|
+
"""
|
22
|
+
Timed function, executes the function at the specified time, by ``default`` it executes at runtime, optionally you can choose the time for execution.
|
23
|
+
|
24
|
+
Parameters:
|
25
|
+
----------
|
26
|
+
`hour_to_exec: 'xx:xx'` - time for function execution, if not passed the value will be by ``default`` at runtime at the time of this function call by the main code.
|
27
|
+
|
28
|
+
``fn_to_exec: function`` - (function) to be called by the handler, if there are parameters in this function they can be passed as next arguments in ``*args`` and ``**kwargs``
|
29
|
+
|
30
|
+
Return:
|
31
|
+
----------
|
32
|
+
>>> type:dict
|
33
|
+
* 'tried': bool - represents if it tried to execute the function passed in the argument
|
34
|
+
* 'success': bool - represents if there was success in trying to execute the requested function
|
35
|
+
|
36
|
+
Example:
|
37
|
+
---------
|
38
|
+
Let's execute the function ``sum`` responsible for adding the values of a and b and return x``sum(a, b) -> x`` and we want the code to wait for the specific time to be executed at ``11:00``
|
39
|
+
>>> exec_at_hour("11:00", sum, 10, 5) -> 15 \n
|
40
|
+
* NOTE: `exec_at_hour` receives as first parameter the function that should be executed, then it can receive the arguments of the function, and explicitly we can define the time for execution.
|
41
|
+
|
42
|
+
Description: pt-br
|
43
|
+
----------
|
44
|
+
Função temporizada, executa a função no horário especificado, por ``default`` executa no momento da chamada em tempo de execução, opcionalmente pode escolher o horário para execução.
|
45
|
+
|
46
|
+
Parâmetros:
|
47
|
+
----------
|
48
|
+
`hour_to_exec: 'xx:xx'` - horário para execução da função, se não for passado o valor será por ``default`` em tempo de execução no momento da chamada desta função pelo cógido principal.
|
49
|
+
|
50
|
+
``fn_to_exec: function`` - (função) a ser chamada pelo handler, se houver parâmetros nessa função podem ser passados como próximos argumentos em ``*args`` e ``**kwargs``
|
51
|
+
|
52
|
+
Retorno:
|
53
|
+
----------
|
54
|
+
>>> type:dict
|
55
|
+
* 'tried': bool - representa se tentou executar a função passada no argumento
|
56
|
+
* 'success': bool - representa se houve sucesso ao tentar executar a função solicitada
|
57
|
+
|
58
|
+
Exemplo:
|
59
|
+
---------
|
60
|
+
Vamos executar a função ``soma`` responsável por somar os valores de a e b e retornar x``soma(a, b) -> x`` e queremos que o código aguarde o horário especifico para ser executado de ``11:00``
|
61
|
+
>>> exec_at_hour("11:00", sum, 10, 5) -> 15 \n
|
62
|
+
* OBS.: `exec_at_hour` recebe como primeiro parâmetro a função que deve ser executada, em seguida pode receber os argumentos da função, e de forma explicitada podemos definir o horário para execução.
|
63
|
+
"""
|
64
|
+
|
65
|
+
# Local Variables
|
66
|
+
result: dict = {
|
67
|
+
'tried': bool,
|
68
|
+
'successs': bool
|
69
|
+
}
|
70
|
+
run: bool
|
71
|
+
now: dt
|
72
|
+
hours: str
|
73
|
+
minutes: str
|
74
|
+
moment_now: str
|
75
|
+
|
76
|
+
try:
|
77
|
+
# Preprocessing
|
78
|
+
run = True
|
79
|
+
now = dt.now()
|
80
|
+
hours = str(now.hour) if now.hour >= 10 else f"0{now.hour}"
|
81
|
+
minutes = str(now.minute) if now.minute >= 10 else f"0{now.minute}"
|
82
|
+
moment_now = f'{hours}:{minutes}'
|
83
|
+
|
84
|
+
if hour_to_exec == None:
|
85
|
+
|
86
|
+
# Process
|
87
|
+
while run:
|
88
|
+
try:
|
89
|
+
fn_to_exec(*args, **kwargs)
|
90
|
+
run = False
|
91
|
+
result['tried'] = not run
|
92
|
+
result['success'] = True
|
93
|
+
success_print(f'{fn_to_exec.__name__}: Successfully executed!')
|
94
|
+
break
|
95
|
+
|
96
|
+
except Exception as e:
|
97
|
+
run = False
|
98
|
+
result['tried'] = not run
|
99
|
+
result['success'] = False
|
100
|
+
error_print(f'An error occurred that prevented the function from executing: {fn_to_exec.__name__} correctly. Error: {str(e)}')
|
101
|
+
break
|
102
|
+
else:
|
103
|
+
# Executes the function call only at the time provided in the argument.
|
104
|
+
while run:
|
105
|
+
if moment_now == hour_to_exec:
|
106
|
+
try:
|
107
|
+
fn_to_exec(*args, **kwargs)
|
108
|
+
run = False
|
109
|
+
result['tried'] = not run
|
110
|
+
result['success'] = True
|
111
|
+
success_print(f'{fn_to_exec.__name__}: Successfully executed!')
|
112
|
+
break
|
113
|
+
|
114
|
+
except Exception as e:
|
115
|
+
run = False
|
116
|
+
result['tried'] = not run
|
117
|
+
result['success'] = False
|
118
|
+
error_print(f'An error occurred that prevented the function from executing: {fn_to_exec.__name__} correctly. Error: {str(e)}')
|
119
|
+
break
|
120
|
+
else:
|
121
|
+
time.sleep(30)
|
122
|
+
now = dt.now()
|
123
|
+
hours = str(now.hour) if now.hour >= 10 else f"0{now.hour}"
|
124
|
+
minutes = str(now.minute) if now.minute >= 10 else f"0{now.minute}"
|
125
|
+
moment_now = f'{hours}:{minutes}'
|
126
|
+
|
127
|
+
return result
|
128
|
+
|
129
|
+
except Exception as e:
|
130
|
+
|
131
|
+
result['success'] = False
|
132
|
+
error_print(f'An error occurred on function from executing: {self.exec_at_hour.__name__}. Error: {str(e)}')
|
133
|
+
return result
|
134
|
+
|
135
|
+
|
136
|
+
def wait_for_exec(self,
|
137
|
+
wait_time: int,
|
138
|
+
fn_to_exec: Callable[..., Any],
|
139
|
+
*args,
|
140
|
+
**kwargs
|
141
|
+
) -> dict[str, bool]:
|
142
|
+
|
143
|
+
"""
|
144
|
+
Timer function, wait for a value in ``seconds`` to execute the function of the argument.
|
145
|
+
|
146
|
+
Parameters:
|
147
|
+
----------
|
148
|
+
`wait_time: int` - (seconds) represents the time that should wait before executing the function passed as an argument.
|
149
|
+
|
150
|
+
``fn_to_exec: function`` - (function) to be called after the waiting time, if there are parameters in this function they can be passed as next arguments of this function in ``*args`` and ``**kwargs``
|
151
|
+
|
152
|
+
Return:
|
153
|
+
----------
|
154
|
+
>>> type:dict
|
155
|
+
* 'success': bool - represents if the action was performed successfully
|
156
|
+
|
157
|
+
Example:
|
158
|
+
---------
|
159
|
+
We have a sum function in the following format ``sum(a, b) -> return x``, where ``x`` is the result of the sum. We want to wait `30 seconds` to execute this function, so:
|
160
|
+
>>> wait_for_exec(30, sum, 10, 5) -> 15 \n
|
161
|
+
* NOTE: `wait_for_exec` receives as first argument the time to wait (sec), then the function `sum` and finally the arguments that the function will use.
|
162
|
+
|
163
|
+
Description: pt-br
|
164
|
+
----------
|
165
|
+
Função temporizadora, aguardar um valor em ``segundos`` para executar a função do argumento.
|
166
|
+
|
167
|
+
Parametros:
|
168
|
+
----------
|
169
|
+
`wait_time: int` - (segundos) representa o tempo que deve aguardar antes de executar a função passada como argumento.
|
170
|
+
|
171
|
+
``fn_to_exec: function`` - (função) a ser chamada depois do tempo aguardado, se houver parametros nessa função podem ser passados como próximos argumentos desta função em ``*args`` e ``**kwargs``
|
172
|
+
|
173
|
+
Retorno:
|
174
|
+
----------
|
175
|
+
>>> type:dict
|
176
|
+
* 'success': bool - representa se ação foi realizada com sucesso
|
177
|
+
|
178
|
+
Exemplo:
|
179
|
+
---------
|
180
|
+
Temos uma função de soma no seguinte formato ``soma(a, b) -> return x``, onde ``x`` é o resultado da soma. Queremos aguardar `30 segundos` para executar essa função, logo:
|
181
|
+
>>> wait_for_exec(30, soma, 10, 5) -> 15 \n
|
182
|
+
* OBS.: `wait_for_exec` recebe como primeiro argumento o tempo a aguardar (seg), depois a função `soma` e por fim os argumentos que a função ira usar.
|
183
|
+
"""
|
184
|
+
|
185
|
+
# Local Variables
|
186
|
+
result: dict = {
|
187
|
+
'success': bool
|
188
|
+
}
|
189
|
+
|
190
|
+
# Process
|
191
|
+
try:
|
192
|
+
time.sleep(wait_time)
|
193
|
+
fn_to_exec(*args, **kwargs)
|
194
|
+
result['success'] = True
|
195
|
+
success_print(f'Function: {self.wait_for_exec.__name__} executed the function: {fn_to_exec.__name__}.')
|
196
|
+
|
197
|
+
except Exception as e:
|
198
|
+
result['success'] = False
|
199
|
+
error_print(f'Error while trying to wait to execute the function: {fn_to_exec.__name__} \nMessage: {str(e)}')
|
200
|
+
|
201
|
+
return result
|
202
|
+
|
203
|
+
|
204
|
+
def exec_and_wait(self,
|
205
|
+
wait_time: int,
|
206
|
+
fn_to_exec: Callable[..., Any],
|
207
|
+
*args,
|
208
|
+
**kwargs
|
209
|
+
) -> dict[str, bool]:
|
210
|
+
|
211
|
+
"""
|
212
|
+
Timer function, executes a function and waits for the time in ``seconds``
|
213
|
+
|
214
|
+
Parameters:
|
215
|
+
----------
|
216
|
+
`wait_time: int` - (seconds) represents the time that should wait after executing the requested function
|
217
|
+
|
218
|
+
``fn_to_exec: function`` - (function) to be called before the time to wait, if there are parameters in this function they can be passed as an argument after the function, being: ``*args`` and ``**kwargs``
|
219
|
+
|
220
|
+
Return:
|
221
|
+
----------
|
222
|
+
>>> type:dict
|
223
|
+
* 'success': bool - represents if the action was performed successfully
|
224
|
+
|
225
|
+
Example:
|
226
|
+
---------
|
227
|
+
We have a sum function in the following format ``sum(a, b) -> return x``, where ``x`` is the result of the sum. We want to execute the sum and then wait `30 seconds` to continue the main code:
|
228
|
+
>>> wait_for_exec(30, sum, 10, 5) -> 15 \n
|
229
|
+
* NOTE: `wait_for_exec` receives as first argument the time to wait (sec), then the function `sum` and finally the arguments that the function will use.
|
230
|
+
|
231
|
+
Description: pt-br
|
232
|
+
----------
|
233
|
+
Função temporizadora, executa uma função e aguarda o tempo em ``segundos``
|
234
|
+
|
235
|
+
Parametros:
|
236
|
+
----------
|
237
|
+
`wait_time: int` - (segundos) representa o tempo que deve aguardar após executar a função solicitada
|
238
|
+
|
239
|
+
``fn_to_exec: function`` - (função) a ser chamada antes do tempo para aguardar, se houver parametros nessa função podem ser passados como argumento depois da função, sendo: ``*args`` e ``**kwargs``
|
240
|
+
|
241
|
+
Retorno:
|
242
|
+
----------
|
243
|
+
>>> type:dict
|
244
|
+
* 'success': bool - representa se ação foi realizada com sucesso
|
245
|
+
|
246
|
+
Exemplo:
|
247
|
+
---------
|
248
|
+
Temos uma função de soma no seguinte formato ``soma(a, b) -> return x``, onde ``x`` é o resultado da soma. Queremos executar a soma e então aguardar `30 segundos` para continuar o código principal:
|
249
|
+
>>> wait_for_exec(30, soma, 10, 5) -> 15 \n
|
250
|
+
* OBS.: `wait_for_exec` recebe como primeiro argumento o tempo a aguardar (seg), depois a função `soma` e por fim os argumentos que a função ira usar.
|
251
|
+
"""
|
252
|
+
|
253
|
+
# Local Variables
|
254
|
+
result: dict = {
|
255
|
+
'success': bool
|
256
|
+
}
|
257
|
+
|
258
|
+
# Process
|
259
|
+
try:
|
260
|
+
fn_to_exec(*args, **kwargs)
|
261
|
+
time.sleep(wait_time)
|
262
|
+
result['success'] = True
|
263
|
+
success_print(f'Function: {self.wait_for_exec.__name__} executed the function: {fn_to_exec.__name__}.')
|
264
|
+
|
265
|
+
except Exception as e:
|
266
|
+
result['success'] = False
|
267
|
+
error_print(f'Error while trying to wait to execute the function: {fn_to_exec.__name__} \nMessage: {str(e)}')
|
268
|
+
|
269
|
+
return result
|
270
|
+
|
271
|
+
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# /date.py
|
2
|
+
|
3
|
+
import datetime as dt
|
4
|
+
from typing import Optional as Op
|
5
|
+
from typing import Tuple
|
6
|
+
from rpa_suite.functions._printer import error_print
|
7
|
+
|
8
|
+
class Date():
|
9
|
+
|
10
|
+
def __init__(self):
|
11
|
+
...
|
12
|
+
|
13
|
+
def get_hms(self) -> Tuple[Op[str], Op[str], Op[str]]:
|
14
|
+
|
15
|
+
"""
|
16
|
+
Function to return hour, minute and second. The return is in the form of a tuple with strings being able to store and use the values individually.
|
17
|
+
|
18
|
+
Treatment:
|
19
|
+
----------
|
20
|
+
The function already does the treatment for values below 10 always keeping 2 decimal places in all results, the individual values are always in string format
|
21
|
+
|
22
|
+
Return:
|
23
|
+
----------
|
24
|
+
>>> type:tuple
|
25
|
+
* tuple('hh', 'mm', 'ss') - tuple with the values of hour, minute and second being able to be stored individually, the values are in string
|
26
|
+
|
27
|
+
Example:
|
28
|
+
---------
|
29
|
+
>>> hour, minute, second = get_hms() \n
|
30
|
+
* NOTE: Note that it is possible to destructure the return to store simultaneously.
|
31
|
+
|
32
|
+
Description: pt-br
|
33
|
+
----------
|
34
|
+
Função para retornar hora, minuto e segundo. O retorno é em forma de tupla com strings podendo armazenar e usar os valores de forma individual.
|
35
|
+
|
36
|
+
Tratamento:
|
37
|
+
----------
|
38
|
+
A função já faz o tratamento para valores abaixo de 10 mantendo sempre 2 casas decimais em todos resultados, os valores individuais são sempre em formato string
|
39
|
+
|
40
|
+
Retorno:
|
41
|
+
----------
|
42
|
+
>>> type:tuple
|
43
|
+
* tuple('hh', 'mm', 'ss') - tupla com os valores de hora, minuto e segundo podendo ser armazenados individualmente, os valores são em string
|
44
|
+
|
45
|
+
Exemplo:
|
46
|
+
---------
|
47
|
+
>>> hora, minuto, segundo = get_hms() \n
|
48
|
+
* OBS.: Note que é possivel desestruturar o retorno para armazenar de forma simultânea.
|
49
|
+
"""
|
50
|
+
|
51
|
+
# Local Variables
|
52
|
+
hours: str
|
53
|
+
minutes: str
|
54
|
+
seconds: str
|
55
|
+
|
56
|
+
try:
|
57
|
+
# Preprocessing
|
58
|
+
now = dt.datetime.now()
|
59
|
+
hours: str = str(now.hour) if now.hour >= 10 else f"0{now.hour}"
|
60
|
+
minutes: str = str(now.minute) if now.minute >= 10 else f"0{now.minute}"
|
61
|
+
seconds: str = str(now.second) if now.second >= 10 else f"0{now.second}"
|
62
|
+
|
63
|
+
# Process
|
64
|
+
try:
|
65
|
+
if len(hours) == 3 or len(minutes) == 3 or len(seconds) == 3:
|
66
|
+
if len(seconds) == 3:
|
67
|
+
seconds[1:]
|
68
|
+
elif len(minutes) == 3:
|
69
|
+
minutes[1:]
|
70
|
+
elif len(hours) == 3:
|
71
|
+
hours[1:]
|
72
|
+
|
73
|
+
return hours, minutes, seconds
|
74
|
+
|
75
|
+
except Exception as e:
|
76
|
+
|
77
|
+
error_print(f'Unable to capture the time. Error: {str(e)}')
|
78
|
+
return None, None, None
|
79
|
+
|
80
|
+
except Exception as e:
|
81
|
+
error_print(f'Error function: {self.get_hms.__name__}! Error: {str(e)}.')
|
82
|
+
return None, None, None
|
83
|
+
|
84
|
+
|
85
|
+
def get_dmy(self) -> Tuple[Op[str], Op[str], Op[str]]:
|
86
|
+
"""
|
87
|
+
Function to return day, month and year. The return is in the form of a tuple with strings being able to store and use the values individually.
|
88
|
+
|
89
|
+
Return:
|
90
|
+
----------
|
91
|
+
>>> type:tuple
|
92
|
+
* tuple('dd', 'mm', 'yy') - tuple with the values of day, month and year being able to be stored individually
|
93
|
+
|
94
|
+
Example:
|
95
|
+
---------
|
96
|
+
>>> day, month, year = get_dmy() \n
|
97
|
+
* NOTE: Note that it is possible to destructure the return to store simultaneously.
|
98
|
+
|
99
|
+
Description: pt-br
|
100
|
+
----------
|
101
|
+
Função para retornar dia, mes e ano. O retorno é em forma de tupla com strings podendo armazenar e usar os valores de forma individual.
|
102
|
+
|
103
|
+
Retorno:
|
104
|
+
----------
|
105
|
+
>>> type:tuple
|
106
|
+
* tuple('dd', 'mm', 'yy') - tupla com os valores de dia, mes e ano podendo ser armazenados individualmente
|
107
|
+
|
108
|
+
Exemplo:
|
109
|
+
---------
|
110
|
+
>>> dia, mes, ano = get_dmy() \n
|
111
|
+
* OBS.: Note que é possivel desestruturar o retorno para armazenar de forma simultânea.
|
112
|
+
"""
|
113
|
+
try:
|
114
|
+
# Local Variables
|
115
|
+
day_got: str
|
116
|
+
month_got: str
|
117
|
+
year_got: str
|
118
|
+
|
119
|
+
# Preprocessing
|
120
|
+
now = dt.datetime.now()
|
121
|
+
|
122
|
+
# Process
|
123
|
+
try:
|
124
|
+
day_got: str = str(now.day) if now.day >= 10 else f"0{now.day}"
|
125
|
+
month_got: str = str(now.month) if now.month >= 10 else f"0{now.month}"
|
126
|
+
year_got: str = str(now.year) if now.year >= 10 else f"0{now.year}"
|
127
|
+
|
128
|
+
return day_got, month_got, year_got
|
129
|
+
|
130
|
+
except Exception as e:
|
131
|
+
|
132
|
+
error_print(f'Unable to capture the time. Error: {str(e)}')
|
133
|
+
return None, None, None
|
134
|
+
|
135
|
+
except Exception as e:
|
136
|
+
error_print(f'Erro function: {self.get_dmy.__name__}! Error: {str(e)}.')
|
137
|
+
return None, None, None
|
138
|
+
|
@@ -0,0 +1,182 @@
|
|
1
|
+
|
2
|
+
import os, shutil
|
3
|
+
from typing import Union
|
4
|
+
from rpa_suite.functions._printer import error_print, alert_print, success_print
|
5
|
+
|
6
|
+
|
7
|
+
class Directory():
|
8
|
+
|
9
|
+
def __init__(self):
|
10
|
+
...
|
11
|
+
|
12
|
+
def create_temp_dir(self,
|
13
|
+
path_to_create: str = 'default',
|
14
|
+
name_temp_dir: str='temp') -> dict[str, Union[bool, str, None]]:
|
15
|
+
|
16
|
+
"""
|
17
|
+
Function responsible for creating a temporary directory to work with files and etc. \n
|
18
|
+
|
19
|
+
Parameters:
|
20
|
+
----------
|
21
|
+
``path_to_create: str`` - should be a string with the full path pointing to the folder where the temporary folder should be created, if it is empty the ``default`` value will be used which will create a folder in the current directory where the file containing this function was called.
|
22
|
+
|
23
|
+
``name_temp_dir: str`` - should be a string representing the name of the temporary directory to be created. If it is empty, the ``temp`` value will be used as the default directory name.
|
24
|
+
|
25
|
+
Return:
|
26
|
+
----------
|
27
|
+
>>> type:dict
|
28
|
+
* 'success': bool - represents case the action was performed successfully
|
29
|
+
* 'path_created': str - path of the directory that was created on the process
|
30
|
+
|
31
|
+
Description: pt-br
|
32
|
+
----------
|
33
|
+
Função responsavel por criar diretório temporário para trabalhar com arquivos e etc. \n
|
34
|
+
|
35
|
+
Parametros:
|
36
|
+
----------
|
37
|
+
``path_to_create: str`` - deve ser uma string com o path completo apontando para a pasta onde deve ser criada a pasta temporaria, se estiver vazio sera usado valor ``default`` que criará pasta no diretório atual onde o arquivo contendo esta função foi chamada.
|
38
|
+
|
39
|
+
``name_temp_dir: str`` - deve ser uma string representando o nome do diretório temporário a ser criado. Se estiver vazio, o valor ``temp`` será usado como o nome padrão do diretório.
|
40
|
+
|
41
|
+
Retorno:
|
42
|
+
----------
|
43
|
+
>>> type:dict
|
44
|
+
* 'success': bool - representa se ação foi realizada com sucesso
|
45
|
+
* 'path_created': str - path do diretório que foi criado no processo
|
46
|
+
"""
|
47
|
+
|
48
|
+
# Local Variables
|
49
|
+
result: dict = {
|
50
|
+
'success': bool,
|
51
|
+
'path_created': str,
|
52
|
+
}
|
53
|
+
|
54
|
+
try:
|
55
|
+
# by 'default', defines path to local script execution path
|
56
|
+
if path_to_create == 'default':
|
57
|
+
path_to_create: str = os.getcwd()
|
58
|
+
|
59
|
+
# Build path to new dir
|
60
|
+
full_path: str = os.path.join(path_to_create, name_temp_dir)
|
61
|
+
|
62
|
+
# Create dir in this block
|
63
|
+
try:
|
64
|
+
|
65
|
+
# Successefully created
|
66
|
+
os.makedirs(full_path, exist_ok=False)
|
67
|
+
|
68
|
+
result['success'] = True
|
69
|
+
result['path_created'] = fr'{full_path}'
|
70
|
+
|
71
|
+
success_print(f"Diretório:'{full_path}' foi criado com sucesso.")
|
72
|
+
|
73
|
+
except FileExistsError:
|
74
|
+
result['success'] = False
|
75
|
+
result['path_created'] = None
|
76
|
+
alert_print(f"Diretório:'{full_path}' já existe.")
|
77
|
+
|
78
|
+
except PermissionError:
|
79
|
+
result['success'] = False
|
80
|
+
result['path_created'] = None
|
81
|
+
alert_print(f"Permissão negada: não é possível criar o diretório '{full_path}'.")
|
82
|
+
|
83
|
+
except Exception as e:
|
84
|
+
result['success'] = False
|
85
|
+
result['path_created'] = None
|
86
|
+
error_print(f'Error capturing current path to create temporary directory! Error: {str(e)}')
|
87
|
+
|
88
|
+
finally:
|
89
|
+
return result
|
90
|
+
|
91
|
+
|
92
|
+
def delete_temp_dir(self,
|
93
|
+
path_to_delete: str = 'default',
|
94
|
+
name_temp_dir: str='temp',
|
95
|
+
delete_files: bool = False) -> dict[str, Union[bool, str, None]]:
|
96
|
+
|
97
|
+
"""
|
98
|
+
Function responsible for deleting a temporary directory. \n
|
99
|
+
|
100
|
+
Parameters:
|
101
|
+
----------
|
102
|
+
``path_to_delete: str`` - should be a string with the full path pointing to the folder where the temporary folder should be deleted, if it is empty the ``default`` value will be used which will delete a folder in the current directory where the file containing this function was called.
|
103
|
+
|
104
|
+
``name_temp_dir: str`` - should be a string representing the name of the temporary directory to be deleted. If it is empty, the ``temp`` value will be used as the default directory name.
|
105
|
+
|
106
|
+
``delete_files: bool`` - should be a boolean indicating whether to delete files in the directory. If it is False, files in the directory will not be deleted.
|
107
|
+
|
108
|
+
Return:
|
109
|
+
----------
|
110
|
+
>>> type:dict
|
111
|
+
* 'success': bool - represents case the action was performed successfully
|
112
|
+
* 'path_deleted': str - path of the directory that was deleted on the process
|
113
|
+
|
114
|
+
Description: pt-br
|
115
|
+
----------
|
116
|
+
Função responsavel por deletar diretório temporário. \n
|
117
|
+
|
118
|
+
Parametros:
|
119
|
+
----------
|
120
|
+
``path_to_delete: str`` - deve ser uma string com o path completo apontando para a pasta onde deve ser deletada a pasta temporaria, se estiver vazio sera usado valor ``default`` que deletará pasta no diretório atual onde o arquivo contendo esta função foi chamada.
|
121
|
+
|
122
|
+
``name_temp_dir: str`` - deve ser uma string representando o nome do diretório temporário a ser deletado. Se estiver vazio, o valor ``temp`` será usado como o nome padrão do diretório.
|
123
|
+
|
124
|
+
``delete_files: bool`` - deve ser um booleano indicando se deve deletar arquivos no diretório. Se for False, arquivos no diretório não serão deletados.
|
125
|
+
|
126
|
+
Retorno:
|
127
|
+
----------
|
128
|
+
>>> type:dict
|
129
|
+
* 'success': bool - representa se ação foi realizada com sucesso
|
130
|
+
* 'path_deleted': str - path do diretório que foi deletado no processo
|
131
|
+
"""
|
132
|
+
|
133
|
+
# Local Variables
|
134
|
+
result: dict = {
|
135
|
+
'success': bool,
|
136
|
+
'path_deleted': str,
|
137
|
+
}
|
138
|
+
|
139
|
+
try:
|
140
|
+
# by 'default', defines path to local script execution path
|
141
|
+
if path_to_delete == 'default':
|
142
|
+
path_to_delete: str = os.getcwd()
|
143
|
+
|
144
|
+
# Build path to new dir
|
145
|
+
full_path: str = os.path.join(path_to_delete, name_temp_dir)
|
146
|
+
|
147
|
+
# Delete dir in this block
|
148
|
+
try:
|
149
|
+
|
150
|
+
# Check if directory exists
|
151
|
+
if os.path.exists(full_path):
|
152
|
+
|
153
|
+
# Check if delete_files is True
|
154
|
+
if delete_files:
|
155
|
+
# Delete all files in the directory
|
156
|
+
shutil.rmtree(full_path)
|
157
|
+
|
158
|
+
else:
|
159
|
+
# Delete the directory only
|
160
|
+
os.rmdir(full_path)
|
161
|
+
|
162
|
+
result['success'] = True
|
163
|
+
result['path_deleted'] = fr'{full_path}'
|
164
|
+
|
165
|
+
success_print(f"Diretório:'{full_path}' foi deletado com sucesso.")
|
166
|
+
else:
|
167
|
+
result['success'] = False
|
168
|
+
result['path_deleted'] = None
|
169
|
+
alert_print(f"Diretório:'{full_path}' não existe.")
|
170
|
+
|
171
|
+
except PermissionError:
|
172
|
+
result['success'] = False
|
173
|
+
result['path_deleted'] = None
|
174
|
+
alert_print(f"Permissão negada: não é possível deletar o diretório '{full_path}'.")
|
175
|
+
|
176
|
+
except Exception as e:
|
177
|
+
result['success'] = False
|
178
|
+
result['path_deleted'] = None
|
179
|
+
error_print(f'Error capturing current path to delete temporary directory! Error: {str(e)}')
|
180
|
+
|
181
|
+
finally:
|
182
|
+
return result
|