-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunciones.py
92 lines (75 loc) · 3.11 KB
/
funciones.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import datetime
import LeerArchivo
import os
import logging
from selenium.webdriver.chrome.options import Options
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def CrearRutaEvidencia():
dir_nameGene="Evidencia"
if not os.path.exists(dir_nameGene):
os.mkdir(dir_nameGene)
now = datetime.datetime.now()
dir_name = "Evidencia_Pruebas_"+now.strftime("%d%m%Y_%H%M%S")
if not os.path.exists(dir_nameGene+"\\"+dir_name):
os.makedirs(dir_nameGene+"\\"+dir_name)
ruta_completa = os.path.abspath(dir_nameGene+"\\"+dir_name)
return ruta_completa
def screenshot(RutaDirectorio,NombreArchivo, driver):
filename = os.path.join(RutaDirectorio, NombreArchivo+".png")
driver.save_screenshot(filename)
return filename
log_filename = 'Asistencia_{}.log'.format(datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))
# Define un mapeo de tipos de log a niveles de registro
nivel_de_registro = {
"INFO": logging.INFO,
"DEBUG": logging.DEBUG,
"WARNING": logging.WARNING,
"ERROR": logging.ERROR,
"CRITICAL": logging.CRITICAL
}
# Configura el nivel de registro y el formato del mensaje
logging.basicConfig(filename=log_filename, level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
def logINFO(message, tipodelog="INFO"):
nivel = nivel_de_registro.get(tipodelog, logging.INFO)
logging.log(nivel, message)
def validar_rut(rut):
rut = rut.replace(".", "").replace("-", "") # Elimina puntos y guiones
if not rut[:-1].isdigit() or (rut[-1] not in '0123456789Kk'):
return False
cuerpo_rut, digito_verificador = rut[:-1], rut[-1]
suma = 0
multiplicador = 2
for digito in reversed(cuerpo_rut):
suma += int(digito) * multiplicador
multiplicador = multiplicador + 1 if multiplicador < 7 else 2
resto = suma % 11
digito_esperado = str(11 - resto) if resto != 0 else '0'
return digito_esperado == digito_verificador.upper()
def EnviaMail(Asunto,Mensaje):
LeerArchivo.LeerArchivo()
# Configura la información del remitente y destinatario
remitente_email = "[email protected]"
remitente_password = "Asado2023*"
destinatario_email = LeerArchivo.MailDestino
# Configura el servidor SMTP de Outlook
smtp_server = "smtp-mail.outlook.com"
smtp_port = 587
# Construye el mensaje
mensaje = MIMEMultipart()
mensaje["From"] = remitente_email
mensaje["To"] = destinatario_email
mensaje["Subject"] = Asunto
# Añade el cuerpo del mensaje
cuerpo_mensaje = f"Estimade \n\n{Mensaje}\n\nSaludos cordiales,\nEquipo By Asistencia"
mensaje.attach(MIMEText(cuerpo_mensaje, "plain"))
# Inicia la conexión al servidor SMTP
with smtplib.SMTP(smtp_server, smtp_port) as server:
# Establece una conexión segura
server.starttls()
# Inicia sesión en la cuenta de correo
server.login(remitente_email, remitente_password)
# Envía el correo electrónico
server.sendmail(remitente_email, destinatario_email, mensaje.as_string())
print("Correo enviado con éxito.")