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.
Files changed (48) hide show
  1. rpa_suite/__init__.py +4 -1
  2. rpa_suite/core/__init__.py +1 -0
  3. rpa_suite/core/clock.py +271 -0
  4. rpa_suite/core/date.py +138 -0
  5. rpa_suite/core/dir.py +182 -0
  6. rpa_suite/core/email.py +343 -0
  7. rpa_suite/core/file.py +209 -0
  8. rpa_suite/core/log.py +304 -0
  9. rpa_suite/core/print.py +197 -0
  10. rpa_suite/core/regex.py +62 -0
  11. rpa_suite/core/validate.py +220 -0
  12. rpa_suite/{log → functions}/__create_log_dir.py +5 -7
  13. rpa_suite/{file → functions}/__create_ss_dir.py +2 -2
  14. rpa_suite/functions/__init__.py +1 -0
  15. rpa_suite/{log → functions}/_functions_logger.py +8 -8
  16. rpa_suite/{log → functions}/_logger.py +3 -3
  17. rpa_suite/suite.py +238 -148
  18. {rpa_suite-1.3.4.dist-info → rpa_suite-1.3.6.dist-info}/METADATA +7 -4
  19. rpa_suite-1.3.6.dist-info/RECORD +25 -0
  20. rpa_suite/clock/__init__.py +0 -1
  21. rpa_suite/clock/exec_at.py +0 -133
  22. rpa_suite/clock/scheduler.py +0 -38
  23. rpa_suite/clock/waiter.py +0 -139
  24. rpa_suite/date/__init__.py +0 -1
  25. rpa_suite/date/date.py +0 -124
  26. rpa_suite/email/__init__.py +0 -1
  27. rpa_suite/email/sender_smtp.py +0 -203
  28. rpa_suite/file/__init__.py +0 -1
  29. rpa_suite/file/counter.py +0 -69
  30. rpa_suite/file/file_flag.py +0 -103
  31. rpa_suite/file/screen_shot.py +0 -91
  32. rpa_suite/file/temp_dir.py +0 -176
  33. rpa_suite/log/__init__.py +0 -1
  34. rpa_suite/log/functions_logger_uru.py +0 -172
  35. rpa_suite/log/log_decorator.py +0 -37
  36. rpa_suite/log/logger_uru.py +0 -110
  37. rpa_suite/regex/__init__.py +0 -1
  38. rpa_suite/regex/pattern_in_text.py +0 -58
  39. rpa_suite/validate/__init__.py +0 -1
  40. rpa_suite/validate/mail_validator.py +0 -93
  41. rpa_suite/validate/string_validator.py +0 -120
  42. rpa_suite-1.3.4.dist-info/RECORD +0 -36
  43. /rpa_suite/{log/printer.py → functions/_printer.py} +0 -0
  44. /rpa_suite/{log → functions}/_variables.py +0 -0
  45. /rpa_suite/{log → functions}/_variables_uru.py +0 -0
  46. {rpa_suite-1.3.4.dist-info → rpa_suite-1.3.6.dist-info}/WHEEL +0 -0
  47. {rpa_suite-1.3.4.dist-info → rpa_suite-1.3.6.dist-info}/licenses/LICENSE +0 -0
  48. {rpa_suite-1.3.4.dist-info → rpa_suite-1.3.6.dist-info}/top_level.txt +0 -0
rpa_suite/suite.py CHANGED
@@ -1,149 +1,239 @@
1
- # suite.py
2
-
3
- """
4
- This file is the heart of the library, acting as a central access point to all available submodules. It imports and instantiates all functions from the submodules into a single object, `Rpa_suite`, allowing users to access all functionalities of the library by importing just this object.
5
-
6
- The structure of the library has been designed to be modular and organized, with each submodule dedicated to a specific type of functionality. Each submodule is contained in its own folder, making the code easier to navigate and maintain.
7
-
8
- Upon installing the library, users only need to import the `Rpa_suite` object to have access to all available functions. This is done through the `invoke` function, which returns an instance of the `Rpa_suite` object.
9
-
10
- Here is an overview of the available submodules:
11
-
12
- - **CLOCK**: Functions related to time, such as waiting for an execution or executing at a specific hour.
13
- - **DATE**: Functions for working with dates.
14
- - **EMAIL**: Functions for sending emails.
15
- - **FILE**: Functions for working with files, such as counting files or creating temporary directories and screenshot too.
16
- - **LOG**: Functions for logging events and printing messages.
17
- - **REGEX**: Functions for working with regular expressions.
18
- - **VALIDATE**: Functions for validating inputs, such as emails or strings.
19
-
20
- Remember, to use the library, just do the following:
21
-
22
- # On your project
23
- from rpa_suite import suite as rpa
24
-
25
- # call functions
26
- rpa.success_print(f'This work!')
27
-
28
- """
29
-
30
- """MODULE CLOCK"""
31
- from .clock.waiter import wait_for_exec, exec_and_wait
32
- from .clock.exec_at import exec_at_hour
33
-
34
-
35
- """MODULE DATE"""
36
- from .date.date import get_hms, get_dmy
37
-
38
-
39
- """MODULE EMAIL"""
40
- from .email.sender_smtp import send_email
41
-
42
-
43
- """MODULE FILE"""
44
- from .file.counter import count_files
45
- from .file.temp_dir import create_temp_dir, delete_temp_dir
46
- from .file.screen_shot import screen_shot
47
- from .file.file_flag import file_flag_create, file_flag_delete
48
-
49
- """MODULE LOG"""
50
- # from .log.loggin import logging_decorator
51
- from .log.printer import alert_print, success_print, error_print, info_print, print_call_fn, print_retur_fn, magenta_print, blue_print
52
-
53
- from .log.logger_uru import config_logger
54
- from .log.functions_logger_uru import log_start_run_debug, log_debug, log_info, log_warning, log_error, log_critical
55
-
56
-
57
- """MODULE REGEX"""
58
- from .regex.pattern_in_text import check_pattern_in_text
59
-
60
-
61
- """MODULE VALIDATE"""
62
- from .validate.mail_validator import valid_emails
63
- from .validate.string_validator import search_str_in
64
-
65
-
66
- class Rpa_suite():
67
-
68
- """
69
- The ``Rpa_suite`` class is a generic representation of the modules, with the aim of centralizing all submodules for access through an instance of this representational Object. It contains variables pointed to the functions of the submodules present in the rpa-site.
70
-
71
- Call
72
- ----------
73
- When calling the maintainer file of this class, an instance of this object will be invoked to be used or reused through another variable
74
-
75
- Objective
76
- ----------
77
- Flexibility being able to call each submodule individually or by importing the representational object of all submodules.
78
-
79
- Description: pt-br
80
- ----------
81
- Classe ``Rpa_suite`` é uma representação genérica do dos módulos, com objetivo de centralizar todos submódulos para acesso através de uma instância deste Objeto representacional. Ele contem variaveis apontadas para as funções dos submódulos presentes no rpa-site.
82
-
83
- Chamada
84
- ----------
85
- Ao chamar o arquivo mantenedor desta classe, sera invocada uma instancia deste objeto para poder ser utilziado ou reutilizado através de outra variável
86
-
87
- Objetivo
88
- ----------
89
- Flexibilidade podendo chamar cada submódulo de forma individual ou fazendo a importação do objeto representacional de todos submódulos.
90
- """
91
-
92
- # clock
93
- wait_for_exec = wait_for_exec
94
- exec_and_wait = exec_and_wait
95
- exec_at_hour = exec_at_hour
96
-
97
- # date
98
- get_hms = get_hms
99
- get_dmy = get_dmy
100
-
101
- # email
102
- send_email = send_email
103
-
104
- # file
105
- count_files = count_files
106
- create_temp_dir = create_temp_dir
107
- delete_temp_dir = delete_temp_dir
108
- screen_shot = screen_shot
109
- file_flag_create = file_flag_create
110
- file_flag_delete = file_flag_delete
111
- #clear_temp_dir = clear_temp_dir
112
-
113
- # log - printer
114
- alert_print = alert_print
115
- success_print = success_print
116
- error_print = error_print
117
- info_print = info_print
118
- print_call_fn = print_call_fn
119
- print_retur_fn = print_retur_fn
120
- magenta_print = magenta_print
121
- blue_print = blue_print
1
+ from .core.clock import Clock
2
+ from .core.date import Date
3
+ from .core.email import Email
4
+ from .core.dir import Directory
5
+ from .core.file import File
6
+ from .core.log import Log
7
+ from .core.print import Print
8
+ from .core.regex import Regex
9
+ from .core.validate import Validate
10
+ from colorama import Fore
11
+
12
+ # Windows bash colors
13
+ class Colors():
14
+ black = f'{Fore.BLACK}'
15
+ blue = f'{Fore.BLUE}'
16
+ green = f'{Fore.GREEN}'
17
+ cyan = f'{Fore.CYAN}'
18
+ red = f'{Fore.RED}'
19
+ magenta = f'{Fore.MAGENTA}'
20
+ yellow = f'{Fore.YELLOW}'
21
+ white = f'{Fore.WHITE}'
22
+ default = f'{Fore.WHITE}'
23
+ call_fn = f'{Fore.LIGHTMAGENTA_EX}'
24
+ retur_fn = f'{Fore.LIGHTYELLOW_EX}'
25
+
26
+ class Suite():
122
27
 
123
- # log - logger with file and prints
124
- config_logger = config_logger
125
- log_start_run_debug = log_start_run_debug
126
- log_debug = log_debug
127
- log_info = log_info
128
- log_warning = log_warning
129
- log_error = log_error
130
- log_critical = log_critical
131
-
132
- # regex
133
- check_pattern_in_text = check_pattern_in_text
134
-
135
- # validate
136
- valid_emails = valid_emails
137
- search_str_in = search_str_in
138
-
139
- # Create a instance of Rpa_suite
140
-
141
- # Define function to return this instance
142
- def invoke() -> Rpa_suite:
143
-
144
- """
145
- Function responsible for return a object Rpa_suite with access all modules by .name_module or use 'from rpa_suite import suite' to >>> suite.functions_avaliable()
146
- """
147
-
148
- suite = Rpa_suite()
149
- return suite
28
+ clock: Clock = Clock()
29
+ date: Date = Date()
30
+ email: Email = Email()
31
+ directory: Directory = Directory()
32
+ file: File = File()
33
+ log: Log = Log()
34
+ printer: Print = Print()
35
+ regex: Regex = Regex()
36
+ validate: Validate = Validate()
37
+
38
+ def __init__(self):
39
+ ...
40
+
41
+ def success_print(self,
42
+ string_text: str,
43
+ color=Colors.green,
44
+ ending="\n") -> None:
45
+ """
46
+ Print that indicates ``SUCCESS``. Customized with the color Green \n
47
+
48
+ Return:
49
+ ----------
50
+ >>> type:None
51
+
52
+ pt-br
53
+ ----------
54
+ Print que indica ``SUCESSO``. Personalizado com a cor Verde \n
55
+
56
+ Retorno:
57
+ ----------
58
+ >>> type:None
59
+ """
60
+ print(f'{color}{string_text}{Colors.default}', end=ending)
61
+
62
+
63
+ def alert_print(self,
64
+ string_text: str,
65
+ color=Colors.yellow,
66
+ ending="\n") -> None:
67
+ """
68
+ Print that indicates ``ALERT``. Customized with the color Yellow \n
69
+
70
+ Return:
71
+ ----------
72
+ >>> type:None
73
+
74
+ pt-br
75
+ ----------
76
+ Print que indica ``ALERTA``. Personalizado com a cor Amarelo \n
77
+ Retorno:
78
+ ----------
79
+ >>> type:None
80
+ """
81
+ print(f'{color}{string_text}{Colors.default}', end=ending)
82
+
83
+
84
+ def info_print(self,
85
+ string_text: str,
86
+ color=Colors.cyan,
87
+ ending="\n") -> None:
88
+ """
89
+ Print that indicates ``INFORMATION``. Customized with the color Cyan \n
90
+
91
+ Return:
92
+ ----------
93
+ >>> type:None
94
+
95
+ pt-br
96
+ ----------
97
+ Print que indica ``INFORMATIVO``. Personalizado com a cor Ciano \n
98
+ Retorno:
99
+ ----------
100
+ >>> type:None
101
+ """
102
+ print(f'{color}{string_text}{Colors.default}', end=ending)
103
+
104
+
105
+ def error_print(self,
106
+ string_text: str,
107
+ color=Colors.red,
108
+ ending="\n") -> None:
109
+ """
110
+ Print that indicates ``ERROR``. Customized with the color Red \n
111
+
112
+ Return:
113
+ ----------
114
+ >>> type:None
115
+
116
+ pt-br
117
+ ----------
118
+ Print que indica ``ERRO``. Personalizado com a cor Vermelho \n
119
+ Retorno:
120
+ ----------
121
+ >>> type:None
122
+ """
123
+ print(f'{color}{string_text}{Colors.default}', end=ending)
124
+
125
+
126
+ def magenta_print(self,
127
+ string_text: str,
128
+ color=Colors.magenta,
129
+ ending="\n") -> None:
130
+ """
131
+ Print customized with the color Magenta \n
132
+
133
+ Return:
134
+ ----------
135
+ >>> type:None
136
+
137
+ pt-br
138
+ ----------
139
+ Print personalizado com a cor Magenta \n
140
+ Retorno:
141
+ ----------
142
+ >>> type:None
143
+ """
144
+ print(f'{color}{string_text}{Colors.default}', end=ending)
145
+
146
+
147
+ def blue_print(self,
148
+ string_text: str,
149
+ color=Colors.blue,
150
+ ending="\n") -> None:
151
+ """
152
+ Print customized with the color Blue \n
153
+
154
+ Return:
155
+ ----------
156
+ >>> type:None
157
+
158
+ pt-br
159
+ ----------
160
+ Print personalizado com a cor Azul \n
161
+ Retorno:
162
+ ----------
163
+ >>> type:None
164
+ """
165
+ print(f'{color}{string_text}{Colors.default}', end=ending)
166
+
167
+
168
+ def print_call_fn(self,
169
+ string_text: str,
170
+ color=Colors.call_fn,
171
+ ending="\n") -> None:
172
+ """
173
+ Print customized for function called (log) \n
174
+ Color: Magenta Light
175
+ Return:
176
+ ----------
177
+ >>> type:None
178
+
179
+ pt-br
180
+ ----------
181
+ Print personalizado para log de chamada de função. \n
182
+ Cor: Magenta Light
183
+ Retorno:
184
+ ----------
185
+ >>> type:None
186
+ """
187
+ print(f'{color}{string_text}{Colors.default}', end=ending)
188
+
189
+
190
+ def print_retur_fn(self,
191
+ string_text: str,
192
+ color=Colors.retur_fn,
193
+ ending="\n") -> None:
194
+ """
195
+ Print customized for function return (log) \n
196
+ Color: Yellow Light
197
+ Return:
198
+ ----------
199
+ >>> type:None
200
+
201
+ pt-br
202
+ ----------
203
+ Print personalizado para log de chamada de função. \n
204
+ Cor: Yellow Light
205
+ Retorno:
206
+ ----------
207
+ >>> type:None
208
+ """
209
+ print(f'{color}{string_text}{Colors.default}', end=ending)
210
+
211
+
212
+ def __install_all_libs(self):
213
+ """
214
+ Metodo responsavel por instalar todas libs para uso avançado do RPA-Suite com todas funcionalidades incluindo OCR e agente de IA
215
+ """
216
+
217
+ import subprocess
218
+ import sys
219
+
220
+ libs = [
221
+ 'colorama',
222
+ 'colorlog',
223
+ 'email_validator',
224
+ 'loguru',
225
+ 'openpyxl',
226
+ 'pandas',
227
+ 'pyautogui',
228
+ 'selenium',
229
+ 'typing',
230
+ 'webdriver_manager'
231
+ ]
232
+
233
+ for lib in libs:
234
+ try:
235
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', lib])
236
+ self.success_print(f'Biblioteca {lib} instalada com sucesso!')
237
+
238
+ except subprocess.CalledProcessError:
239
+ self.error_print(f'Erro ao instalar biblioteca {lib}')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rpa_suite
3
- Version: 1.3.4
3
+ Version: 1.3.6
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.2
189
+ ### Notas da atualização: 1.3.6
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*
@@ -0,0 +1,25 @@
1
+ rpa_suite/__init__.py,sha256=a01Ua3RpUt57HOYjAoBdjOhnnGIexnVxDrBmRLWgJvo,71
2
+ rpa_suite/suite.py,sha256=o5xxt4oIJhKFnFeeFnf-Lue19KZlBUcMRA_9Dyc615w,6550
3
+ rpa_suite/core/__init__.py,sha256=VROMsrhKGMqUlstH8cEqp5fwRVC12d3U3_XoxoKOzyg,28
4
+ rpa_suite/core/clock.py,sha256=qGF_fn0_n19WX4GLtzCrwrJmna9HtzfrhLYramOGZm8,12709
5
+ rpa_suite/core/date.py,sha256=dgg-A5GL67MPFP5_0Ie61ymC9pCyDmoVgCJ10zzStrw,5363
6
+ rpa_suite/core/dir.py,sha256=cwwvlPeXFEsoVFdu38Jsfw98t3CbshdS79m5D_y2txQ,7848
7
+ rpa_suite/core/email.py,sha256=zu0G6HEEIocV48RfQKAkwZIyEswwJ40RRSrNh5PEf-8,15098
8
+ rpa_suite/core/file.py,sha256=AgXmlyU_AiJ54sKwa8aTWyCjVUfuFhC9-0_m6U6zS7Y,8916
9
+ rpa_suite/core/log.py,sha256=t5TEMHuWMkx9psbbeIyPy3VHs8MJDaSh1h0rdMaYnro,10841
10
+ rpa_suite/core/print.py,sha256=PvEBm7TNNdZFa_qNX67i1JmPVToTBe7I1tQ73B17Onk,5122
11
+ rpa_suite/core/regex.py,sha256=Q2FRI-aUB6oUXunK_0f9sc5kfbZt1qnZb4w7YbzST2o,2602
12
+ rpa_suite/core/validate.py,sha256=J23xB_nXymPKR8eNJb844LJ2OETSPwFT8m2JawbTVz0,9134
13
+ rpa_suite/functions/__create_log_dir.py,sha256=-NjH3Mwv8Aa0EgZiD_TcdlSKbsoYl5EoYmPclFwjTKY,3325
14
+ rpa_suite/functions/__create_ss_dir.py,sha256=WMuDDTxM5xWudQjftC7xPr6y3IdiXjVK-GfxkQNIo4c,3377
15
+ rpa_suite/functions/__init__.py,sha256=aa0jejVvnghufR50owKcKpmYit7XVAliyN9gn9JkdLE,33
16
+ rpa_suite/functions/_functions_logger.py,sha256=hlYDEUsmmfwaPlY_YQeNQEFeT_mryHBqgBVyRdxge48,2703
17
+ rpa_suite/functions/_logger.py,sha256=gTYO9JlbX5_jDfu_4FTTajJw3_GotE2BHUbDDB1Hf5g,3643
18
+ rpa_suite/functions/_printer.py,sha256=r72zeobAi2baVbYgbfFH0h5-WMv4tSDGPNlcpZen7O0,3949
19
+ rpa_suite/functions/_variables.py,sha256=vCcktifFUriBQTyUaayZW8BlE8Gr7VP-tFbfomKOS5U,312
20
+ rpa_suite/functions/_variables_uru.py,sha256=xRqYp49l1fFNrHczOmJ6Pqw1PKIWs0f9kxlgvuYGYys,303
21
+ rpa_suite-1.3.6.dist-info/licenses/LICENSE,sha256=5D8PIbs31iGd9i1_MDNg4SzaQnp9sEIULALh2y3WyMI,1102
22
+ rpa_suite-1.3.6.dist-info/METADATA,sha256=QoSFZO5O9geMr67jiVDgiq-cz5u4_a0cA9mOwciOR6Q,9348
23
+ rpa_suite-1.3.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
24
+ rpa_suite-1.3.6.dist-info/top_level.txt,sha256=HYkDtg-kJNAr3F2XAIPyJ-QBbNhk7q6jrqsFt10lz4Y,10
25
+ rpa_suite-1.3.6.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- # /__init__.py
@@ -1,133 +0,0 @@
1
- # /exec_at.py
2
-
3
- import time
4
- from typing import Callable, Any
5
- from datetime import datetime as dt
6
- from rpa_suite.log.printer import error_print, success_print
7
-
8
- def exec_at_hour(
9
- time_waiting: int,
10
- hour_to_exec: str,
11
- fn_to_exec: Callable[..., Any],
12
- *args,
13
- **kwargs) -> dict[str, bool]:
14
-
15
- """
16
- Timed function, executes the function at the specified time, by ``default`` it executes at runtime, optionally you can choose the time for execution.
17
-
18
- Parameters:
19
- ----------
20
- `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.
21
-
22
- ``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``
23
-
24
- Return:
25
- ----------
26
- >>> type:dict
27
- * 'tried': bool - represents if it tried to execute the function passed in the argument
28
- * 'success': bool - represents if there was success in trying to execute the requested function
29
-
30
- Example:
31
- ---------
32
- 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``
33
- >>> exec_at_hour("11:00", sum, 10, 5) -> 15 \n
34
- * 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.
35
-
36
- Description: pt-br
37
- ----------
38
- 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.
39
-
40
- Parâmetros:
41
- ----------
42
- `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.
43
-
44
- ``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``
45
-
46
- Retorno:
47
- ----------
48
- >>> type:dict
49
- * 'tried': bool - representa se tentou executar a função passada no argumento
50
- * 'success': bool - representa se houve sucesso ao tentar executar a função solicitada
51
-
52
- Exemplo:
53
- ---------
54
- 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``
55
- >>> exec_at_hour("11:00", sum, 10, 5) -> 15 \n
56
- * 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.
57
- """
58
-
59
- # Local Variables
60
- result: dict = {
61
- 'tried': bool,
62
- 'successs': bool
63
- }
64
- run: bool
65
- now: dt
66
- hours: str
67
- minutes: str
68
- moment_now: str
69
-
70
- try:
71
- # Preprocessing
72
- run = True
73
- now = dt.now()
74
- hours = str(now.hour) if now.hour >= 10 else f"0{now.hour}"
75
- minutes = str(now.minute) if now.minute >= 10 else f"0{now.minute}"
76
- moment_now = f'{hours}:{minutes}'
77
-
78
- if hour_to_exec == None:
79
-
80
- # Process
81
- while run:
82
- try:
83
- fn_to_exec(*args, **kwargs)
84
- run = False
85
- result['tried'] = not run
86
- result['success'] = True
87
- success_print(f'{fn_to_exec.__name__}: Successfully executed!')
88
- break
89
-
90
- except Exception as e:
91
- run = False
92
- result['tried'] = not run
93
- result['success'] = False
94
- error_print(f'An error occurred that prevented the function from executing: {fn_to_exec.__name__} correctly. Error: {str(e)}')
95
- break
96
- else:
97
- # Executes the function call only at the time provided in the argument.
98
- while run:
99
- if moment_now == hour_to_exec:
100
- try:
101
- fn_to_exec(*args, **kwargs)
102
- run = False
103
- result['tried'] = not run
104
- result['success'] = True
105
- success_print(f'{fn_to_exec.__name__}: Successfully executed!')
106
- break
107
-
108
- except Exception as e:
109
- run = False
110
- result['tried'] = not run
111
- result['success'] = False
112
- error_print(f'An error occurred that prevented the function from executing: {fn_to_exec.__name__} correctly. Error: {str(e)}')
113
- break
114
- else:
115
-
116
- # interval to new validate hour
117
- if time_waiting:
118
- time.sleep(time_waiting)
119
- else:
120
- time.sleep(9)
121
-
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: {fn_to_exec.__name__}. Error: {str(e)}')
133
- return result
@@ -1,38 +0,0 @@
1
- # /scheduler.py
2
-
3
- import schedule
4
- import time
5
- import subprocess
6
-
7
- def run_python_script(script_path):
8
- try:
9
- subprocess.run(['python', script_path], check=True)
10
- except subprocess.CalledProcessError as e:
11
- print(f"Erro ao executar o script {script_path}: {e}")
12
-
13
- def batch1():
14
- # Substitua 'script1.py' pelo caminho do primeiro script Python que deseja executar
15
- run_python_script('script1.py')
16
-
17
- def batch2():
18
- # Substitua 'script2.py' pelo caminho do segundo script Python que deseja executar
19
- run_python_script('script2.py')
20
-
21
- def batch3():
22
- # Substitua 'script3.py' pelo caminho do terceiro script Python que deseja executar
23
- run_python_script('script3.py')
24
-
25
- print("Aguardando nova execução...")
26
-
27
- # Horário para executar o primeiro batch (substitua com o horário desejado)
28
- schedule.every().day.at("08:00").do(batch1)
29
-
30
- # Horário para executar o segundo batch (substitua com o horário desejado)
31
- schedule.every().day.at("12:00").do(batch2)
32
-
33
- # Horário para executar o terceiro batch (substitua com o horário desejado)
34
- schedule.every().day.at("16:00").do(batch3)
35
-
36
- while True:
37
- schedule.run_pending()
38
- time.sleep(1)