rpa-suite 1.3.3__py3-none-any.whl → 1.3.5__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.3.dist-info → rpa_suite-1.3.5.dist-info}/METADATA +66 -55
- rpa_suite-1.3.5.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.3.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.3.dist-info → rpa_suite-1.3.5.dist-info}/WHEEL +0 -0
- {rpa_suite-1.3.3.dist-info → rpa_suite-1.3.5.dist-info}/licenses/LICENSE +0 -0
- {rpa_suite-1.3.3.dist-info → rpa_suite-1.3.5.dist-info}/top_level.txt +0 -0
rpa_suite/clock/exec_at.py
DELETED
@@ -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
|
rpa_suite/clock/scheduler.py
DELETED
@@ -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)
|
rpa_suite/clock/waiter.py
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
# /waiter.py
|
2
|
-
|
3
|
-
import time
|
4
|
-
from typing import Callable, Any
|
5
|
-
from rpa_suite.log.printer import error_print, success_print
|
6
|
-
|
7
|
-
def wait_for_exec(
|
8
|
-
wait_time: int,
|
9
|
-
fn_to_exec: Callable[..., Any],
|
10
|
-
*args,
|
11
|
-
**kwargs
|
12
|
-
) -> dict[str, bool]:
|
13
|
-
|
14
|
-
"""
|
15
|
-
Timer function, wait for a value in ``seconds`` to execute the function of the argument.
|
16
|
-
|
17
|
-
Parameters:
|
18
|
-
----------
|
19
|
-
`wait_time: int` - (seconds) represents the time that should wait before executing the function passed as an argument.
|
20
|
-
|
21
|
-
``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``
|
22
|
-
|
23
|
-
Return:
|
24
|
-
----------
|
25
|
-
>>> type:dict
|
26
|
-
* 'success': bool - represents if the action was performed successfully
|
27
|
-
|
28
|
-
Example:
|
29
|
-
---------
|
30
|
-
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:
|
31
|
-
>>> wait_for_exec(30, sum, 10, 5) -> 15 \n
|
32
|
-
* 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.
|
33
|
-
|
34
|
-
Description: pt-br
|
35
|
-
----------
|
36
|
-
Função temporizadora, aguardar um valor em ``segundos`` para executar a função do argumento.
|
37
|
-
|
38
|
-
Parametros:
|
39
|
-
----------
|
40
|
-
`wait_time: int` - (segundos) representa o tempo que deve aguardar antes de executar a função passada como argumento.
|
41
|
-
|
42
|
-
``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``
|
43
|
-
|
44
|
-
Retorno:
|
45
|
-
----------
|
46
|
-
>>> type:dict
|
47
|
-
* 'success': bool - representa se ação foi realizada com sucesso
|
48
|
-
|
49
|
-
Exemplo:
|
50
|
-
---------
|
51
|
-
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:
|
52
|
-
>>> wait_for_exec(30, soma, 10, 5) -> 15 \n
|
53
|
-
* 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.
|
54
|
-
"""
|
55
|
-
|
56
|
-
# Local Variables
|
57
|
-
result: dict = {
|
58
|
-
'success': bool
|
59
|
-
}
|
60
|
-
|
61
|
-
# Process
|
62
|
-
try:
|
63
|
-
time.sleep(wait_time)
|
64
|
-
fn_to_exec(*args, **kwargs)
|
65
|
-
result['success'] = True
|
66
|
-
success_print(f'Function: {wait_for_exec.__name__} executed the function: {fn_to_exec.__name__}.')
|
67
|
-
|
68
|
-
except Exception as e:
|
69
|
-
result['success'] = False
|
70
|
-
error_print(f'Error while trying to wait to execute the function: {fn_to_exec.__name__} \nMessage: {str(e)}')
|
71
|
-
|
72
|
-
return result
|
73
|
-
|
74
|
-
def exec_and_wait(
|
75
|
-
wait_time: int,
|
76
|
-
fn_to_exec: Callable[..., Any],
|
77
|
-
*args,
|
78
|
-
**kwargs
|
79
|
-
) -> dict[str, bool]:
|
80
|
-
|
81
|
-
"""
|
82
|
-
Timer function, executes a function and waits for the time in ``seconds``
|
83
|
-
|
84
|
-
Parameters:
|
85
|
-
----------
|
86
|
-
`wait_time: int` - (seconds) represents the time that should wait after executing the requested function
|
87
|
-
|
88
|
-
``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``
|
89
|
-
|
90
|
-
Return:
|
91
|
-
----------
|
92
|
-
>>> type:dict
|
93
|
-
* 'success': bool - represents if the action was performed successfully
|
94
|
-
|
95
|
-
Example:
|
96
|
-
---------
|
97
|
-
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:
|
98
|
-
>>> wait_for_exec(30, sum, 10, 5) -> 15 \n
|
99
|
-
* 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.
|
100
|
-
|
101
|
-
Description: pt-br
|
102
|
-
----------
|
103
|
-
Função temporizadora, executa uma função e aguarda o tempo em ``segundos``
|
104
|
-
|
105
|
-
Parametros:
|
106
|
-
----------
|
107
|
-
`wait_time: int` - (segundos) representa o tempo que deve aguardar após executar a função solicitada
|
108
|
-
|
109
|
-
``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``
|
110
|
-
|
111
|
-
Retorno:
|
112
|
-
----------
|
113
|
-
>>> type:dict
|
114
|
-
* 'success': bool - representa se ação foi realizada com sucesso
|
115
|
-
|
116
|
-
Exemplo:
|
117
|
-
---------
|
118
|
-
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:
|
119
|
-
>>> wait_for_exec(30, soma, 10, 5) -> 15 \n
|
120
|
-
* 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.
|
121
|
-
"""
|
122
|
-
|
123
|
-
# Local Variables
|
124
|
-
result: dict = {
|
125
|
-
'success': bool
|
126
|
-
}
|
127
|
-
|
128
|
-
# Process
|
129
|
-
try:
|
130
|
-
fn_to_exec(*args, **kwargs)
|
131
|
-
time.sleep(wait_time)
|
132
|
-
result['success'] = True
|
133
|
-
success_print(f'Function: {wait_for_exec.__name__} executed the function: {fn_to_exec.__name__}.')
|
134
|
-
|
135
|
-
except Exception as e:
|
136
|
-
result['success'] = False
|
137
|
-
error_print(f'Error while trying to wait to execute the function: {fn_to_exec.__name__} \nMessage: {str(e)}')
|
138
|
-
|
139
|
-
return result
|
rpa_suite/date/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# /__init__.py
|
rpa_suite/date/date.py
DELETED
@@ -1,124 +0,0 @@
|
|
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.log.printer import error_print
|
7
|
-
|
8
|
-
|
9
|
-
def get_hms() -> Tuple[Op[str], Op[str], Op[str]]:
|
10
|
-
|
11
|
-
"""
|
12
|
-
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.
|
13
|
-
|
14
|
-
Treatment:
|
15
|
-
----------
|
16
|
-
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
|
17
|
-
|
18
|
-
Return:
|
19
|
-
----------
|
20
|
-
>>> type:tuple
|
21
|
-
* tuple('hh', 'mm', 'ss') - tuple with the values of hour, minute and second being able to be stored individually, the values are in string
|
22
|
-
|
23
|
-
Example:
|
24
|
-
---------
|
25
|
-
>>> hour, minute, second = get_hms() \n
|
26
|
-
* NOTE: Note that it is possible to destructure the return to store simultaneously.
|
27
|
-
|
28
|
-
Description: pt-br
|
29
|
-
----------
|
30
|
-
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.
|
31
|
-
|
32
|
-
Tratamento:
|
33
|
-
----------
|
34
|
-
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
|
35
|
-
|
36
|
-
Retorno:
|
37
|
-
----------
|
38
|
-
>>> type:tuple
|
39
|
-
* tuple('hh', 'mm', 'ss') - tupla com os valores de hora, minuto e segundo podendo ser armazenados individualmente, os valores são em string
|
40
|
-
|
41
|
-
Exemplo:
|
42
|
-
---------
|
43
|
-
>>> hora, minuto, segundo = get_hms() \n
|
44
|
-
* OBS.: Note que é possivel desestruturar o retorno para armazenar de forma simultânea.
|
45
|
-
"""
|
46
|
-
|
47
|
-
# Local Variables
|
48
|
-
hours: str
|
49
|
-
minutes: str
|
50
|
-
seconds: str
|
51
|
-
|
52
|
-
# Preprocessing
|
53
|
-
now = dt.datetime.now()
|
54
|
-
hours: str = str(now.hour) if now.hour >= 10 else f"0{now.hour}"
|
55
|
-
minutes: str = str(now.minute) if now.minute >= 10 else f"0{now.minute}"
|
56
|
-
seconds: str = str(now.second) if now.second >= 10 else f"0{now.second}"
|
57
|
-
|
58
|
-
# Process
|
59
|
-
try:
|
60
|
-
if len(hours) == 3 or len(minutes) == 3 or len(seconds) == 3:
|
61
|
-
if len(seconds) == 3:
|
62
|
-
seconds[1:]
|
63
|
-
elif len(minutes) == 3:
|
64
|
-
minutes[1:]
|
65
|
-
elif len(hours) == 3:
|
66
|
-
hours[1:]
|
67
|
-
|
68
|
-
return hours, minutes, seconds
|
69
|
-
|
70
|
-
except Exception as e:
|
71
|
-
|
72
|
-
error_print(f'Unable to capture the time. Error: {str(e)}')
|
73
|
-
return None, None, None
|
74
|
-
|
75
|
-
|
76
|
-
def get_dmy() -> Tuple[Op[str], Op[str], Op[str]]:
|
77
|
-
"""
|
78
|
-
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.
|
79
|
-
|
80
|
-
Return:
|
81
|
-
----------
|
82
|
-
>>> type:tuple
|
83
|
-
* tuple('dd', 'mm', 'yy') - tuple with the values of day, month and year being able to be stored individually
|
84
|
-
|
85
|
-
Example:
|
86
|
-
---------
|
87
|
-
>>> day, month, year = get_dmy() \n
|
88
|
-
* NOTE: Note that it is possible to destructure the return to store simultaneously.
|
89
|
-
|
90
|
-
Description: pt-br
|
91
|
-
----------
|
92
|
-
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.
|
93
|
-
|
94
|
-
Retorno:
|
95
|
-
----------
|
96
|
-
>>> type:tuple
|
97
|
-
* tuple('dd', 'mm', 'yy') - tupla com os valores de dia, mes e ano podendo ser armazenados individualmente
|
98
|
-
|
99
|
-
Exemplo:
|
100
|
-
---------
|
101
|
-
>>> dia, mes, ano = get_dmy() \n
|
102
|
-
* OBS.: Note que é possivel desestruturar o retorno para armazenar de forma simultânea.
|
103
|
-
"""
|
104
|
-
|
105
|
-
# Local Variables
|
106
|
-
day_got: str
|
107
|
-
month_got: str
|
108
|
-
year_got: str
|
109
|
-
|
110
|
-
# Preprocessing
|
111
|
-
now = dt.datetime.now()
|
112
|
-
|
113
|
-
# Process
|
114
|
-
try:
|
115
|
-
day_got: str = str(now.day) if now.day >= 10 else f"0{now.day}"
|
116
|
-
month_got: str = str(now.month) if now.month >= 10 else f"0{now.month}"
|
117
|
-
year_got: str = str(now.year) if now.year >= 10 else f"0{now.year}"
|
118
|
-
|
119
|
-
return day_got, month_got, year_got
|
120
|
-
|
121
|
-
except Exception as e:
|
122
|
-
|
123
|
-
error_print(f'Unable to capture the time. Error: {str(e)}')
|
124
|
-
return None, None, None
|
rpa_suite/email/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# /__init__.py
|
rpa_suite/email/sender_smtp.py
DELETED
@@ -1,203 +0,0 @@
|
|
1
|
-
# /sender_smtp.py
|
2
|
-
|
3
|
-
import smtplib, os
|
4
|
-
from email.mime.image import MIMEImage
|
5
|
-
from email.mime.multipart import MIMEMultipart
|
6
|
-
from email.mime.text import MIMEText
|
7
|
-
from email.mime.base import MIMEBase
|
8
|
-
from email import encoders
|
9
|
-
from rpa_suite.log.printer import alert_print, error_print, success_print
|
10
|
-
from rpa_suite.validate.mail_validator import email_validator
|
11
|
-
|
12
|
-
def send_email(
|
13
|
-
email_from: str,
|
14
|
-
pass_from: str,
|
15
|
-
email_to: list[str],
|
16
|
-
subject_title: str,
|
17
|
-
body_message: str,
|
18
|
-
image_footer: str = None,
|
19
|
-
attachments: list[str] = None,
|
20
|
-
type_content: str = 'html',
|
21
|
-
smtp_server: str = 'smtp.office365.com',
|
22
|
-
smtp_port: int = 587,
|
23
|
-
authentication_tls: bool = True,
|
24
|
-
) -> dict:
|
25
|
-
|
26
|
-
"""
|
27
|
-
Function responsible for sending emails ``(SMTP)``, accepts ``list of recipients`` and possibility
|
28
|
-
of ``attaching files``. \n
|
29
|
-
|
30
|
-
Parameters:
|
31
|
-
----------
|
32
|
-
``email_from: str`` - email from who will send the email.
|
33
|
-
``pass_from: str`` - password of the account used, advised to isolate the password elsewhere.
|
34
|
-
``email_to: list[str]`` - list of emails to which the emails will be sent.
|
35
|
-
``subject_title: str`` - email title.
|
36
|
-
``body_message: str``- body message of the email.
|
37
|
-
``image_footer: str`` - image footer of body message of the email.
|
38
|
-
``attachments: list[str]`` - list with path of attachments if any. (default None).
|
39
|
-
``type_content: str`` - type of message content can be 'plain' or 'html' (default 'html').
|
40
|
-
``smtp_server: str`` - server to be used to connect with the email account (default 'smtp.office365.com')
|
41
|
-
``smtp_port: int`` - port to be used on this server (default 587 - TLS), commum use 465 for SSL authentication
|
42
|
-
``authentication_tls: bool`` - authentication method (default True), if False use SSL authentication
|
43
|
-
|
44
|
-
Return:
|
45
|
-
----------
|
46
|
-
>>> type:dict
|
47
|
-
a dictionary with all information that may be necessary about the emails.
|
48
|
-
Respectively being:
|
49
|
-
* 'success': bool - if there was at least one successful shipment
|
50
|
-
* 'all_mails': list - list of all emails parameterized for sending
|
51
|
-
* 'valid_mails': list - list of all valid emails for sending
|
52
|
-
* 'invalid_mails': list - list of all invalid emails for sending
|
53
|
-
* 'qt_mails_sent': int - effective quantity that was sent
|
54
|
-
* 'attchament': bool - if there are attachments
|
55
|
-
* 'qt_attach': int - how many attachments were inserted
|
56
|
-
|
57
|
-
Description: pt-br
|
58
|
-
----------
|
59
|
-
Função responsavel por enviar emails ``(SMTP)``, aceita ``lista de destinatários`` e possibilidade
|
60
|
-
de ``anexar arquivos``. \n
|
61
|
-
|
62
|
-
Parametros:
|
63
|
-
----------
|
64
|
-
``email_from: str`` - email de quem ira enviar o email.
|
65
|
-
``pass_from: str`` - senha da conta utilizada, aconselhado isolar a senha em outro local.
|
66
|
-
``email_to: list[str]`` - lista de emails para os quais serão enviados os emails.
|
67
|
-
``subject_title: str`` - titulo do email.
|
68
|
-
``body_message: str``- mensagem do corpo do email.
|
69
|
-
``image_footer: str`` - imagem de rodapé do corpo do email.
|
70
|
-
``attachments: list[str]`` - lista com caminho de anexos se houver. (default None).
|
71
|
-
``type_content: str`` - tipo de conteudo da mensagem pode ser 'plain' ou 'html' (default 'html').
|
72
|
-
``smtp_server: str`` - servidor a ser utilizado para conectar com a conta de email (default 'smtp.office365.com')
|
73
|
-
``smtp_port: int`` - porta a ser utilizada nesse servidor (default 587 - TLS), comum usar 465 para autenticação por SSL
|
74
|
-
``authentication_tls: bool`` - metódo de autenticação (default True), caso Falso usa autenticação por SSL
|
75
|
-
|
76
|
-
Retorno:
|
77
|
-
----------
|
78
|
-
>>> type:dict
|
79
|
-
um dicionário com todas informações que podem ser necessarias sobre os emails.
|
80
|
-
Sendo respectivamente:
|
81
|
-
* 'success': bool - se houve pelo menos um envio com sucesso
|
82
|
-
* 'all_mails': list - lista de todos emails parametrizados para envio
|
83
|
-
* 'valid_mails': list - lista de todos emails validos para envio
|
84
|
-
* 'invalid_mails': list - lista de todos emails invalidos para envio
|
85
|
-
* 'qt_mails_sent': int - quantidade efetiva que foi realizado envio
|
86
|
-
* 'attchament': bool - se há anexos
|
87
|
-
* 'qt_attach': int - quantos anexos foram inseridos
|
88
|
-
"""
|
89
|
-
|
90
|
-
# Local Variables
|
91
|
-
result: dict = {
|
92
|
-
'success': bool,
|
93
|
-
'all_mails': list,
|
94
|
-
'valid_mails': list,
|
95
|
-
'invalid_mails': list,
|
96
|
-
'qt_mails_sent': int,
|
97
|
-
'attchament': bool,
|
98
|
-
'qt_attach': int
|
99
|
-
}
|
100
|
-
email_valido = []
|
101
|
-
email_invalido = []
|
102
|
-
|
103
|
-
# Preprocessing
|
104
|
-
result['success'] = False
|
105
|
-
result['qt_mails_sent'] = 0
|
106
|
-
result['attchament'] = False
|
107
|
-
|
108
|
-
msg = MIMEMultipart()
|
109
|
-
msg['From'] = email_from
|
110
|
-
msg['Subject'] = subject_title
|
111
|
-
|
112
|
-
# Email Body Content
|
113
|
-
msg.attach(MIMEText(body_message, type_content))
|
114
|
-
|
115
|
-
# Add image Footer
|
116
|
-
if image_footer:
|
117
|
-
try:
|
118
|
-
with open(image_footer, 'rb') as img:
|
119
|
-
msg_image = MIMEImage(img.read())
|
120
|
-
msg_image.add_header('Content-ID', '<logo>')
|
121
|
-
# Notice: Content-ID correlact at "cid" on tag <img> at body mail
|
122
|
-
msg.attach(msg_image)
|
123
|
-
except FileNotFoundError as e:
|
124
|
-
alert_print(f'File Not Found! Error: {str(e)}')
|
125
|
-
except Exception as e:
|
126
|
-
error_print(f'An Error ocurred, during set image: <{image_footer}> as MIMEImage! Error: {str(e)}')
|
127
|
-
|
128
|
-
# Add Attachment
|
129
|
-
if attachments:
|
130
|
-
result['qt_attach'] = 0
|
131
|
-
result['attchament'] = True
|
132
|
-
for path_to_attach in attachments:
|
133
|
-
file_name = os.path.basename(path_to_attach)
|
134
|
-
attachs = open(path_to_attach, 'rb')
|
135
|
-
part = MIMEBase('application', 'octet-stream')
|
136
|
-
part.set_payload((attachs).read())
|
137
|
-
encoders.encode_base64(part)
|
138
|
-
part.add_header('Content-Disposition', "attachment; filename= %s" % file_name)
|
139
|
-
msg.attach(part)
|
140
|
-
result['qt_attach'] += 1
|
141
|
-
else:
|
142
|
-
result['attchament'] = False
|
143
|
-
result['qt_attach'] = 0
|
144
|
-
|
145
|
-
# SMTP server config
|
146
|
-
try:
|
147
|
-
|
148
|
-
# authentication TLS True -> Using TLS
|
149
|
-
if authentication_tls:
|
150
|
-
|
151
|
-
server_by_smtp = smtplib.SMTP(smtp_server, smtp_port)
|
152
|
-
server_by_smtp.starttls()
|
153
|
-
server_by_smtp.login(email_from, pass_from)
|
154
|
-
email_content = msg.as_string()
|
155
|
-
|
156
|
-
else: # authentication TLS False -> Using SSL
|
157
|
-
|
158
|
-
# connect SMTP server using SSL
|
159
|
-
server_by_smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
|
160
|
-
server_by_smtp.login(email_from, pass_from)
|
161
|
-
email_content = msg.as_string()
|
162
|
-
|
163
|
-
# Treats the email list before trying to send, keeping only valid emails
|
164
|
-
try:
|
165
|
-
for emails in email_to:
|
166
|
-
try:
|
167
|
-
v = email_validator.validate_email(emails)
|
168
|
-
email_valido.append(emails)
|
169
|
-
|
170
|
-
except email_validator.EmailNotValidError:
|
171
|
-
email_invalido.append(emails)
|
172
|
-
|
173
|
-
except Exception as e:
|
174
|
-
error_print(f'Error while trying to validate email list: {str(e)}')
|
175
|
-
|
176
|
-
# Attaches the treated email list to perform the sending
|
177
|
-
msg['To'] = ', '.join(email_valido)
|
178
|
-
for email in email_valido:
|
179
|
-
try:
|
180
|
-
server_by_smtp.sendmail(email_from, email, email_content)
|
181
|
-
result['qt_mails_sent'] += 1
|
182
|
-
result['all_mails'] = email_to
|
183
|
-
|
184
|
-
except smtplib.SMTPException as e:
|
185
|
-
error_print(f"The email: {email} don't sent, caused by error: {str(e)}")
|
186
|
-
|
187
|
-
#server_by_smtp.quit()
|
188
|
-
result['success'] = True
|
189
|
-
success_print(f'Email(s) Sent!')
|
190
|
-
|
191
|
-
|
192
|
-
except smtplib.SMTPException as e:
|
193
|
-
result['success'] = False
|
194
|
-
error_print(f'Error while trying sent Email: {str(e)}')
|
195
|
-
|
196
|
-
finally:
|
197
|
-
server_by_smtp.quit()
|
198
|
-
|
199
|
-
# Postprocessing
|
200
|
-
result['valid_mails'] = email_valido
|
201
|
-
result['invalid_mails'] = email_invalido
|
202
|
-
|
203
|
-
return result
|
rpa_suite/file/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# /__init__.py
|