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/core/clock.py CHANGED
@@ -9,19 +9,18 @@ from typing import Callable, Any
9
9
  from datetime import datetime as dt
10
10
 
11
11
 
12
- class Clock():
13
-
12
+ class Clock:
14
13
  """
15
14
  Class that provides utilities for time manipulation and stopwatch.
16
-
15
+
17
16
  This class offers functionalities for:
18
17
  - Timed function execution
19
18
  - Execution time control
20
19
  - Task scheduling
21
-
20
+
22
21
  Methods:
23
22
  exec_at_hour: Executes a function at a specific time
24
-
23
+
25
24
  The Clock class is part of RPA Suite and can be accessed through the rpa object:
26
25
  >>> from rpa_suite import rpa
27
26
  >>> rpa.clock.exec_at_hour("14:30", my_function)
@@ -29,110 +28,108 @@ class Clock():
29
28
  pt-br
30
29
  ----------
31
30
  Classe que fornece utilitários para manipulação de tempo e cronômetro.
32
-
31
+
33
32
  Esta classe oferece funcionalidades para:
34
33
  - Execução temporizada de funções
35
34
  - Controle de tempo de execução
36
35
  - Agendamento de tarefas
37
-
36
+
38
37
  Métodos:
39
38
  exec_at_hour: Executa uma função em um horário específico
40
-
39
+
41
40
  A classe Clock é parte do RPA Suite e pode ser acessada através do objeto rpa:
42
41
  >>> from rpa_suite import rpa
43
42
  >>> rpa.clock.exec_at_hour("14:30", minha_funcao)
44
43
  """
45
44
 
46
- def __init__(self):
47
- ...
48
-
49
- def exec_at_hour(self,
50
- hour_to_exec: str | None,
51
- fn_to_exec: Callable[..., Any],
52
- *args,
53
- **kwargs,
54
- ) -> dict[str, bool]:
55
-
45
+ def __init__(self): ...
46
+
47
+ def exec_at_hour(
48
+ self,
49
+ hour_to_exec: str | None,
50
+ fn_to_exec: Callable[..., Any],
51
+ *args,
52
+ **kwargs,
53
+ ) -> dict[str, bool]:
56
54
  """
57
55
  Timed function, executes the function at the specified time, by ``default`` it executes at runtime, optionally you can choose the time for execution.
58
-
56
+
59
57
  Parameters:
60
58
  ----------
61
59
  `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.
62
-
60
+
63
61
  ``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``
64
-
62
+
65
63
  Return:
66
64
  ----------
67
65
  >>> type:dict
68
66
  * 'tried': bool - represents if it tried to execute the function passed in the argument
69
67
  * 'success': bool - represents if there was success in trying to execute the requested function
70
-
68
+
71
69
  Example:
72
70
  ---------
73
71
  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``
74
72
  >>> exec_at_hour("11:00", sum, 10, 5) -> 15 \n
75
73
  * 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.
76
-
74
+
77
75
  Description: pt-br
78
- ----------
76
+ ----------
79
77
  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.
80
-
78
+
81
79
  Parâmetros:
82
80
  ----------
83
81
  `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.
84
-
82
+
85
83
  ``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``
86
-
84
+
87
85
  Retorno:
88
86
  ----------
89
87
  >>> type:dict
90
88
  * 'tried': bool - representa se tentou executar a função passada no argumento
91
89
  * 'success': bool - representa se houve sucesso ao tentar executar a função solicitada
92
-
90
+
93
91
  Exemplo:
94
92
  ---------
95
93
  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``
96
94
  >>> exec_at_hour("11:00", sum, 10, 5) -> 15 \n
97
95
  * 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.
98
96
  """
99
-
97
+
100
98
  # Local Variables
101
- result: dict = {
102
- 'tried': bool,
103
- 'successs': bool
104
- }
99
+ result: dict = {"tried": bool, "successs": bool}
105
100
  run: bool
106
101
  now: dt
107
102
  hours: str
108
103
  minutes: str
109
104
  moment_now: str
110
-
105
+
111
106
  try:
112
107
  # Preprocessing
113
108
  run = True
114
109
  now = dt.now()
115
110
  hours = str(now.hour) if now.hour >= 10 else f"0{now.hour}"
116
111
  minutes = str(now.minute) if now.minute >= 10 else f"0{now.minute}"
117
- moment_now = f'{hours}:{minutes}'
118
-
112
+ moment_now = f"{hours}:{minutes}"
113
+
119
114
  if hour_to_exec == None:
120
-
115
+
121
116
  # Process
122
117
  while run:
123
118
  try:
124
119
  fn_to_exec(*args, **kwargs)
125
120
  run = False
126
- result['tried'] = not run
127
- result['success'] = True
128
- success_print(f'{fn_to_exec.__name__}: Successfully executed!')
121
+ result["tried"] = not run
122
+ result["success"] = True
123
+ success_print(f"{fn_to_exec.__name__}: Successfully executed!")
129
124
  break
130
-
125
+
131
126
  except Exception as e:
132
127
  run = False
133
- result['tried'] = not run
134
- result['success'] = False
135
- error_print(f'An error occurred that prevented the function from executing: {fn_to_exec.__name__} correctly. Error: {str(e)}')
128
+ result["tried"] = not run
129
+ result["success"] = False
130
+ error_print(
131
+ f"An error occurred that prevented the function from executing: {fn_to_exec.__name__} correctly. Error: {str(e)}"
132
+ )
136
133
  break
137
134
  else:
138
135
  # Executes the function call only at the time provided in the argument.
@@ -141,168 +138,168 @@ class Clock():
141
138
  try:
142
139
  fn_to_exec(*args, **kwargs)
143
140
  run = False
144
- result['tried'] = not run
145
- result['success'] = True
146
- success_print(f'{fn_to_exec.__name__}: Successfully executed!')
141
+ result["tried"] = not run
142
+ result["success"] = True
143
+ success_print(
144
+ f"{fn_to_exec.__name__}: Successfully executed!"
145
+ )
147
146
  break
148
-
147
+
149
148
  except Exception as e:
150
149
  run = False
151
- result['tried'] = not run
152
- result['success'] = False
153
- error_print(f'An error occurred that prevented the function from executing: {fn_to_exec.__name__} correctly. Error: {str(e)}')
150
+ result["tried"] = not run
151
+ result["success"] = False
152
+ error_print(
153
+ f"An error occurred that prevented the function from executing: {fn_to_exec.__name__} correctly. Error: {str(e)}"
154
+ )
154
155
  break
155
156
  else:
156
157
  time.sleep(30)
157
158
  now = dt.now()
158
159
  hours = str(now.hour) if now.hour >= 10 else f"0{now.hour}"
159
- minutes = str(now.minute) if now.minute >= 10 else f"0{now.minute}"
160
- moment_now = f'{hours}:{minutes}'
160
+ minutes = (
161
+ str(now.minute) if now.minute >= 10 else f"0{now.minute}"
162
+ )
163
+ moment_now = f"{hours}:{minutes}"
161
164
 
162
165
  return result
163
-
166
+
164
167
  except Exception as e:
165
-
166
- result['success'] = False
167
- error_print(f'An error occurred on function from executing: {self.exec_at_hour.__name__}. Error: {str(e)}')
168
- return result
169
168
 
169
+ result["success"] = False
170
+ error_print(
171
+ f"An error occurred on function from executing: {self.exec_at_hour.__name__}. Error: {str(e)}"
172
+ )
173
+ return result
170
174
 
171
- def wait_for_exec(self,
172
- wait_time: int,
173
- fn_to_exec: Callable[..., Any],
174
- *args,
175
- **kwargs
176
- ) -> dict[str, bool]:
177
-
175
+ def wait_for_exec(
176
+ self, wait_time: int, fn_to_exec: Callable[..., Any], *args, **kwargs
177
+ ) -> dict[str, bool]:
178
178
  """
179
179
  Timer function, wait for a value in ``seconds`` to execute the function of the argument.
180
-
180
+
181
181
  Parameters:
182
182
  ----------
183
183
  `wait_time: int` - (seconds) represents the time that should wait before executing the function passed as an argument.
184
-
184
+
185
185
  ``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``
186
-
186
+
187
187
  Return:
188
188
  ----------
189
189
  >>> type:dict
190
190
  * 'success': bool - represents if the action was performed successfully
191
-
191
+
192
192
  Example:
193
193
  ---------
194
194
  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:
195
195
  >>> wait_for_exec(30, sum, 10, 5) -> 15 \n
196
196
  * 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.
197
-
198
-
197
+
198
+
199
199
  pt-br
200
- ----------
200
+ ----------
201
201
  Função temporizadora, aguardar um valor em ``segundos`` para executar a função do argumento.
202
-
202
+
203
203
  Parametros:
204
204
  ----------
205
205
  `wait_time: int` - (segundos) representa o tempo que deve aguardar antes de executar a função passada como argumento.
206
-
206
+
207
207
  ``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``
208
-
208
+
209
209
  Retorno:
210
210
  ----------
211
211
  >>> type:dict
212
212
  * 'success': bool - representa se ação foi realizada com sucesso
213
-
213
+
214
214
  Exemplo:
215
215
  ---------
216
216
  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:
217
217
  >>> wait_for_exec(30, soma, 10, 5) -> 15 \n
218
218
  * 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.
219
219
  """
220
-
220
+
221
221
  # Local Variables
222
- result: dict = {
223
- 'success': bool
224
- }
225
-
222
+ result: dict = {"success": bool}
223
+
226
224
  # Process
227
225
  try:
228
226
  time.sleep(wait_time)
229
227
  fn_to_exec(*args, **kwargs)
230
- result['success'] = True
231
- success_print(f'Function: {self.wait_for_exec.__name__} executed the function: {fn_to_exec.__name__}.')
232
-
228
+ result["success"] = True
229
+ success_print(
230
+ f"Function: {self.wait_for_exec.__name__} executed the function: {fn_to_exec.__name__}."
231
+ )
232
+
233
233
  except Exception as e:
234
- result['success'] = False
235
- error_print(f'Error while trying to wait to execute the function: {fn_to_exec.__name__} \nMessage: {str(e)}')
236
-
237
- return result
234
+ result["success"] = False
235
+ error_print(
236
+ f"Error while trying to wait to execute the function: {fn_to_exec.__name__} \nMessage: {str(e)}"
237
+ )
238
238
 
239
+ return result
239
240
 
240
- def exec_and_wait(self,
241
- wait_time: int,
242
- fn_to_exec: Callable[..., Any],
243
- *args,
244
- **kwargs
245
- ) -> dict[str, bool]:
246
-
241
+ def exec_and_wait(
242
+ self, wait_time: int, fn_to_exec: Callable[..., Any], *args, **kwargs
243
+ ) -> dict[str, bool]:
247
244
  """
248
245
  Timer function, executes a function and waits for the time in ``seconds``
249
-
246
+
250
247
  Parameters:
251
248
  ----------
252
249
  `wait_time: int` - (seconds) represents the time that should wait after executing the requested function
253
-
250
+
254
251
  ``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``
255
-
252
+
256
253
  Return:
257
254
  ----------
258
255
  >>> type:dict
259
256
  * 'success': bool - represents if the action was performed successfully
260
-
257
+
261
258
  Example:
262
259
  ---------
263
260
  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:
264
261
  >>> wait_for_exec(30, sum, 10, 5) -> 15 \n
265
262
  * 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.
266
-
267
-
263
+
264
+
268
265
  pt-br
269
266
  ----------
270
267
  Função temporizadora, executa uma função e aguarda o tempo em ``segundos``
271
-
268
+
272
269
  Parametros:
273
270
  ----------
274
271
  `wait_time: int` - (segundos) representa o tempo que deve aguardar após executar a função solicitada
275
-
272
+
276
273
  ``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``
277
-
274
+
278
275
  Retorno:
279
276
  ----------
280
277
  >>> type:dict
281
278
  * 'success': bool - representa se ação foi realizada com sucesso
282
-
279
+
283
280
  Exemplo:
284
281
  ---------
285
282
  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:
286
283
  >>> wait_for_exec(30, soma, 10, 5) -> 15 \n
287
284
  * 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.
288
285
  """
289
-
286
+
290
287
  # Local Variables
291
- result: dict = {
292
- 'success': bool
293
- }
294
-
288
+ result: dict = {"success": bool}
289
+
295
290
  # Process
296
291
  try:
297
292
  fn_to_exec(*args, **kwargs)
298
293
  time.sleep(wait_time)
299
- result['success'] = True
300
- success_print(f'Function: {self.wait_for_exec.__name__} executed the function: {fn_to_exec.__name__}.')
301
-
302
- except Exception as e:
303
- result['success'] = False
304
- error_print(f'Error while trying to wait to execute the function: {fn_to_exec.__name__} \nMessage: {str(e)}')
305
-
306
- return result
294
+ result["success"] = True
295
+ success_print(
296
+ f"Function: {self.wait_for_exec.__name__} executed the function: {fn_to_exec.__name__}."
297
+ )
307
298
 
299
+ except Exception as e:
300
+ result["success"] = False
301
+ error_print(
302
+ f"Error while trying to wait to execute the function: {fn_to_exec.__name__} \nMessage: {str(e)}"
303
+ )
308
304
 
305
+ return result
rpa_suite/core/date.py CHANGED
@@ -9,19 +9,18 @@ from typing import Optional as Op
9
9
  from typing import Tuple
10
10
 
11
11
 
12
- class Date():
13
-
12
+ class Date:
14
13
  """
15
14
  Class that provides utilities for date manipulation and formatting.
16
-
15
+
17
16
  This class offers functionalities for:
18
17
  - Getting current time components (hours, minutes, seconds)
19
18
  - Date formatting and manipulation
20
19
  - Date validation and conversion
21
-
20
+
22
21
  Methods:
23
22
  get_hms: Returns current time as tuple of hour, minute, second
24
-
23
+
25
24
  The Date class is part of RPA Suite and can be accessed through the rpa object:
26
25
  >>> from rpa_suite import rpa
27
26
  >>> hour, minute, second = rpa.date.get_hms()
@@ -29,72 +28,71 @@ class Date():
29
28
  pt-br
30
29
  ----------
31
30
  Classe que fornece utilitários para manipulação e formatação de datas.
32
-
31
+
33
32
  Esta classe oferece funcionalidades para:
34
33
  - Obtenção de componentes do tempo atual (horas, minutos, segundos)
35
34
  - Formatação e manipulação de datas
36
35
  - Validação e conversão de datas
37
-
36
+
38
37
  Métodos:
39
38
  get_hms: Retorna o horário atual como tupla de hora, minuto, segundo
40
-
39
+
41
40
  A classe Date é parte do RPA Suite e pode ser acessada através do objeto rpa:
42
41
  >>> from rpa_suite import rpa
43
42
  >>> hora, minuto, segundo = rpa.date.get_hms()
44
43
  """
45
- def __init__(self):
46
- ...
44
+
45
+ def __init__(self): ...
47
46
 
48
47
  def get_hms(self) -> Tuple[Op[str], Op[str], Op[str]]:
49
-
50
48
  """
51
49
  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.
52
-
50
+
53
51
  Treatment:
54
52
  ----------
55
53
  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
56
-
54
+
57
55
  Return:
58
56
  ----------
59
57
  >>> type:tuple
60
58
  * tuple('hh', 'mm', 'ss') - tuple with the values of hour, minute and second being able to be stored individually, the values are in string
61
-
59
+
62
60
  Example:
63
61
  ---------
64
62
  >>> hour, minute, second = get_hms() \n
65
63
  * NOTE: Note that it is possible to destructure the return to store simultaneously.
66
-
64
+
67
65
  Description: pt-br
68
66
  ----------
69
67
  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.
70
-
68
+
71
69
  Tratamento:
72
70
  ----------
73
71
  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
74
-
72
+
75
73
  Retorno:
76
74
  ----------
77
75
  >>> type:tuple
78
76
  * tuple('hh', 'mm', 'ss') - tupla com os valores de hora, minuto e segundo podendo ser armazenados individualmente, os valores são em string
79
-
77
+
80
78
  Exemplo:
81
79
  ---------
82
80
  >>> hora, minuto, segundo = get_hms() \n
83
81
  * OBS.: Note que é possivel desestruturar o retorno para armazenar de forma simultânea.
84
82
  """
85
-
83
+
86
84
  # Local Variables
87
85
  hours: str
88
86
  minutes: str
89
87
  seconds: str
90
-
88
+
91
89
  try:
92
90
  # Preprocessing
93
91
  now = dt.datetime.now()
94
92
  hours: str = str(now.hour) if now.hour >= 10 else f"0{now.hour}"
95
93
  minutes: str = str(now.minute) if now.minute >= 10 else f"0{now.minute}"
96
94
  seconds: str = str(now.second) if now.second >= 10 else f"0{now.second}"
97
-
95
+
98
96
  # Process
99
97
  try:
100
98
  if len(hours) == 3 or len(minutes) == 3 or len(seconds) == 3:
@@ -104,42 +102,41 @@ class Date():
104
102
  minutes[1:]
105
103
  elif len(hours) == 3:
106
104
  hours[1:]
107
-
105
+
108
106
  return hours, minutes, seconds
109
-
107
+
110
108
  except Exception as e:
111
109
 
112
- error_print(f'Unable to capture the time. Error: {str(e)}')
110
+ error_print(f"Unable to capture the time. Error: {str(e)}")
113
111
  return None, None, None
114
-
112
+
115
113
  except Exception as e:
116
- error_print(f'Error function: {self.get_hms.__name__}! Error: {str(e)}.')
114
+ error_print(f"Error function: {self.get_hms.__name__}! Error: {str(e)}.")
117
115
  return None, None, None
118
116
 
119
-
120
117
  def get_dmy(self) -> Tuple[Op[str], Op[str], Op[str]]:
121
118
  """
122
119
  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.
123
-
120
+
124
121
  Return:
125
122
  ----------
126
123
  >>> type:tuple
127
124
  * tuple('dd', 'mm', 'yy') - tuple with the values of day, month and year being able to be stored individually
128
-
125
+
129
126
  Example:
130
127
  ---------
131
128
  >>> day, month, year = get_dmy() \n
132
129
  * NOTE: Note that it is possible to destructure the return to store simultaneously.
133
-
130
+
134
131
  Description: pt-br
135
132
  ----------
136
133
  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.
137
-
134
+
138
135
  Retorno:
139
136
  ----------
140
137
  >>> type:tuple
141
138
  * tuple('dd', 'mm', 'yy') - tupla com os valores de dia, mes e ano podendo ser armazenados individualmente
142
-
139
+
143
140
  Exemplo:
144
141
  ---------
145
142
  >>> dia, mes, ano = get_dmy() \n
@@ -150,24 +147,23 @@ class Date():
150
147
  day_got: str
151
148
  month_got: str
152
149
  year_got: str
153
-
150
+
154
151
  # Preprocessing
155
152
  now = dt.datetime.now()
156
-
153
+
157
154
  # Process
158
155
  try:
159
156
  day_got: str = str(now.day) if now.day >= 10 else f"0{now.day}"
160
157
  month_got: str = str(now.month) if now.month >= 10 else f"0{now.month}"
161
158
  year_got: str = str(now.year) if now.year >= 10 else f"0{now.year}"
162
-
159
+
163
160
  return day_got, month_got, year_got
164
-
161
+
165
162
  except Exception as e:
166
163
 
167
- error_print(f'Unable to capture the time. Error: {str(e)}')
164
+ error_print(f"Unable to capture the time. Error: {str(e)}")
168
165
  return None, None, None
169
-
166
+
170
167
  except Exception as e:
171
- error_print(f'Erro function: {self.get_dmy.__name__}! Error: {str(e)}.')
168
+ error_print(f"Erro function: {self.get_dmy.__name__}! Error: {str(e)}.")
172
169
  return None, None, None
173
-