-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ijara/2-send-email
2 send email
- Loading branch information
Showing
4 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,4 +165,5 @@ cython_debug/ | |
.env | ||
config.py | ||
#daily/ | ||
pdf/ | ||
pdf/ | ||
emails.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
OPENAI_API_KEY='apikey' | ||
OPENAI_API_KEY='apikey' | ||
EMAIL_USER='[email protected]' | ||
EMAIL_PASSWORD='Jpg1995' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,25 @@ def descargar_pdfs(pdf_urls): | |
print(f"Todos los PDFs han sido descargados en: {carpeta_dia}") | ||
return carpeta_dia | ||
|
||
def enviar_email(texto): | ||
from redmail import EmailSender | ||
email = EmailSender( | ||
host="smtp.gmail.com", | ||
port=587, | ||
username=EMAIL_USER, | ||
password=EMAIL_PASSWORD, | ||
) | ||
|
||
# Example emails.txt content: | ||
# [email protected] | ||
# [email protected] | ||
# [email protected] | ||
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 | ||
) | ||
|
||
def cargar_pdf_a_chatgpt(ruta_pdf): | ||
print(f"Intentando cargar PDF a ChatGPT: {os.path.basename(ruta_pdf)}") | ||
|
@@ -160,7 +179,16 @@ def main(): | |
|
||
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() | ||
|
||
|
||
|
@@ -237,5 +265,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() |