From e0588cfc716df774072712985e03a9564bc34889 Mon Sep 17 00:00:00 2001 From: Ignacio Jara Date: Tue, 12 Nov 2024 14:37:30 -0300 Subject: [PATCH 1/3] sending email correctly --- config.py.bak | 4 +++- main.py | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config.py.bak b/config.py.bak index b267fd9..b59adad 100644 --- a/config.py.bak +++ b/config.py.bak @@ -1 +1,3 @@ -OPENAI_API_KEY='apikey' \ No newline at end of file +OPENAI_API_KEY='apikey' +EMAIL_USER='ijara756@gmail.com' +EMAIL_PASSWORD='Jpg1995' \ No newline at end of file diff --git a/main.py b/main.py index 4db7540..6c0df77 100644 --- a/main.py +++ b/main.py @@ -103,9 +103,16 @@ def descargar_pdfs(pdf_urls): def enviar_email(texto): from redmail import EmailSender email = EmailSender( - + host="smtp.gmail.com", + port=587, + username=EMAIL_USER, + password=EMAIL_PASSWORD, + ) + email.receivers = ['ijara756@icloud.com'] + email.send( + subject="Newsletter Diario Oficial - " + datetime.datetime.now().strftime("%Y%m%d"), + html=texto ) - def cargar_pdf_a_chatgpt(ruta_pdf): print(f"Intentando cargar PDF a ChatGPT: {os.path.basename(ruta_pdf)}") instruccion = "resume la informacion con titulo y descripcion, no mas de 2 parrafos, debe ser facil de entender y sin tecnicismos, debe explicar lo sucede, si existen requisitos, deberes o derechos debe listarlos usando el tag li, output using html5 only p and h1 tags, los cve no estan relacionados con temas de ciberseguridad, descarta firma electronica aprobaciones o similares" @@ -160,11 +167,20 @@ def cargar_pdf_a_chatgpt(ruta_pdf): return None def main(): - debug = False # Variable de depuración + debug = True # Variable de depuración if debug: print("Modo de depuración activado.") - + try: + with open('docs/latest.html', 'r', encoding='utf-8') as archivo: + contenido = archivo.read() + print("Contenido de latest.html:") + print(contenido) + enviar_email(contenido) + except FileNotFoundError: + print("El archivo docs/latest.html no existe") + except Exception as e: + print(f"Error al leer el archivo: {str(e)}") sys.exit() @@ -242,5 +258,6 @@ def main(): if __name__ == "__main__": from config import OPENAI_API_KEY # Importa la clave API desde un archivo de configuración + from config import EMAIL_USER, EMAIL_PASSWORD openai.api_key = OPENAI_API_KEY # Usa la variable importada para la API key de OpenAI main() From cc9a28da0d80385b5e30d9776fcd93916a1ac8f2 Mon Sep 17 00:00:00 2001 From: Ignacio Jara Date: Tue, 12 Nov 2024 14:40:47 -0300 Subject: [PATCH 2/3] lista dinamica de correos --- .gitignore | 3 ++- emails.txt.bak | 1 + main.py | 8 +++++++- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 emails.txt.bak diff --git a/.gitignore b/.gitignore index 0a7add7..f171536 100644 --- a/.gitignore +++ b/.gitignore @@ -165,4 +165,5 @@ cython_debug/ .env config.py #daily/ -pdf/ \ No newline at end of file +pdf/ +emails.txt \ No newline at end of file diff --git a/emails.txt.bak b/emails.txt.bak new file mode 100644 index 0000000..323923d --- /dev/null +++ b/emails.txt.bak @@ -0,0 +1 @@ +mail@mail.com \ No newline at end of file diff --git a/main.py b/main.py index 6c0df77..2f05d3e 100644 --- a/main.py +++ b/main.py @@ -108,7 +108,13 @@ def enviar_email(texto): username=EMAIL_USER, password=EMAIL_PASSWORD, ) - email.receivers = ['ijara756@icloud.com'] + + # Example emails.txt content: + # ijara756@icloud.com + # another@email.com + # third@email.com + with open('emails.txt', 'r') as f: + email.receivers = [line.strip() for line in f if line.strip()] email.send( subject="Newsletter Diario Oficial - " + datetime.datetime.now().strftime("%Y%m%d"), html=texto From 938992b2f2f0bb0636c2257ce8606e8048a8796a Mon Sep 17 00:00:00 2001 From: Ignacio Jara Date: Tue, 12 Nov 2024 14:41:45 -0300 Subject: [PATCH 3/3] debug off --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2f05d3e..ed8768c 100644 --- a/main.py +++ b/main.py @@ -173,7 +173,7 @@ def cargar_pdf_a_chatgpt(ruta_pdf): return None def main(): - debug = True # Variable de depuración + debug = False # Variable de depuración if debug: print("Modo de depuración activado.")