Spaces:
Running
Running
Tu Nombre commited on
Commit ·
c27889b
1
Parent(s): 6f06aaa
avisos por gmail/brevo
Browse files
main.py
CHANGED
|
@@ -84,22 +84,28 @@ def enviar_email(email, nicho, url):
|
|
| 84 |
|
| 85 |
CLIENTES = {}
|
| 86 |
|
| 87 |
-
def
|
| 88 |
try:
|
| 89 |
import requests as _r
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
except Exception as e:
|
| 97 |
-
print(f"Error
|
| 98 |
|
| 99 |
def avisar_telegram(mensaje):
|
| 100 |
-
"""Manda
|
| 101 |
import threading
|
| 102 |
-
|
|
|
|
| 103 |
|
| 104 |
def cargar_clientes():
|
| 105 |
global CLIENTES
|
|
|
|
| 84 |
|
| 85 |
CLIENTES = {}
|
| 86 |
|
| 87 |
+
def _enviar_aviso_real(asunto, mensaje):
|
| 88 |
try:
|
| 89 |
import requests as _r
|
| 90 |
+
html = mensaje.replace("<b>", "<strong>").replace("</b>", "</strong>").replace("\n", "<br>")
|
| 91 |
+
_r.post("https://api.brevo.com/v3/smtp/email",
|
| 92 |
+
headers={"api-key": os.environ.get("BREVO_KEY",""), "Content-Type": "application/json", "accept": "application/json"},
|
| 93 |
+
json={
|
| 94 |
+
"sender": {"name": "TubeBot Avisos", "email": "dayron100813@gmail.com"},
|
| 95 |
+
"to": [{"email": "dayron100813@gmail.com"}],
|
| 96 |
+
"subject": asunto,
|
| 97 |
+
"htmlContent": f"<div style='font-family:sans-serif;background:#0a0a0a;color:#fff;padding:20px'>{html}</div>"
|
| 98 |
+
},
|
| 99 |
+
timeout=30
|
| 100 |
+
)
|
| 101 |
except Exception as e:
|
| 102 |
+
print(f"Error aviso: {e}", flush=True)
|
| 103 |
|
| 104 |
def avisar_telegram(mensaje):
|
| 105 |
+
"""Manda aviso por Gmail (Brevo) en thread aparte"""
|
| 106 |
import threading
|
| 107 |
+
asunto_corto = mensaje.split("\n")[0].replace("<b>", "").replace("</b>", "").strip()
|
| 108 |
+
threading.Thread(target=_enviar_aviso_real, args=(asunto_corto[:100], mensaje), daemon=True).start()
|
| 109 |
|
| 110 |
def cargar_clientes():
|
| 111 |
global CLIENTES
|