|
|
@@ -1,7 +1,6 @@
|
|
|
import csv
|
|
|
import os
|
|
|
import json
|
|
|
-import re
|
|
|
import secrets
|
|
|
from typing import List, Dict, Union, Annotated
|
|
|
|
|
|
@@ -16,10 +15,14 @@ from starlette.middleware.sessions import SessionMiddleware
|
|
|
from impresora.printer import PrinterUSB
|
|
|
from impresora.order import *
|
|
|
|
|
|
+import smtplib
|
|
|
+from email.message import EmailMessage
|
|
|
+
|
|
|
# Load environment variables from .env file
|
|
|
load_dotenv()
|
|
|
#pruebitas4
|
|
|
|
|
|
+
|
|
|
# Configuration
|
|
|
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
|
PORT = int(os.getenv("PORT", 6001))
|
|
|
@@ -54,6 +57,74 @@ app.add_middleware(
|
|
|
BG_DATA_PATH = os.path.join(os.path.dirname(__file__), 'data.json')
|
|
|
PRODUCTS_PATH = os.path.join(os.path.dirname(__file__), 'products.json')
|
|
|
|
|
|
+
|
|
|
+def send_email():
|
|
|
+ # Datos del remitente
|
|
|
+ EMAIL_ORIGEN = 'expresspedidos211@gmail.com'
|
|
|
+ EMAIL_DESTINO = ['erwinjacimino2003@gmail.com', "mompyn@gmail.com"]
|
|
|
+ CONTRASENA = 'drkassszdtgapufg'
|
|
|
+
|
|
|
+
|
|
|
+ # Crear el correo
|
|
|
+ msg = EmailMessage()
|
|
|
+ msg['Subject'] = 'Impresora Desconectada weon :('
|
|
|
+ msg['From'] = EMAIL_ORIGEN
|
|
|
+ msg['To'] = ", ".join(EMAIL_DESTINO)
|
|
|
+ msg.set_content('Este correo tiene contenido HTML.')
|
|
|
+ msg.add_alternative("""
|
|
|
+ <html>
|
|
|
+ <body style="margin:0; padding:0; background-color:#5a67d8; font-family: Arial, sans-serif;">
|
|
|
+ <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="padding: 40px 0;">
|
|
|
+ <tr>
|
|
|
+ <td align="center">
|
|
|
+ <table border="0" cellpadding="0" cellspacing="0" width="500" style="background-color: #e3e3e3; border-radius: 25px; padding: 40px; text-align: center;">
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <div style="font-size: 60px; background-color: #ff6b6b; width: 80px; height: 80px; line-height: 80px; border-radius: 15px; margin: 0 auto 20px; color: white;">
|
|
|
+ 🖨️
|
|
|
+ </div>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <img src="https://media4.giphy.com/media/v1.Y2lkPTc5MGI3NjExZGlraDhpb2tkeHEweDZ2eWdnZDZlNXFvODhmNzZieWN6OXp0b3ZqNCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/3hetVnNSl0IBa/giphy.gif" alt="Gatito peleando con la impresora" width="250" style="border-radius: 12px; margin-bottom: 20px;" />
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <h1 style="font-size: 24px; color: #ff6b6b; margin-bottom: 10px;">¡Impresora Desconectada!</h1>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <p style="font-size: 16px; color: #333333; line-height: 1.5; margin-bottom: 20px;">
|
|
|
+ No se puede establecer conexión con la impresora.<br>
|
|
|
+ Por favor, verifica la conexión y vuelve a intentarlo.
|
|
|
+ </p>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span style="display: inline-block; background: #ff6b6b; color: white; padding: 12px 24px; border-radius: 25px; font-weight: bold; font-size: 16px;">
|
|
|
+ 🔴 Estado: Desconectada
|
|
|
+ </span>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ </table>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ </table>
|
|
|
+ </body>
|
|
|
+ </html>
|
|
|
+
|
|
|
+ """, subtype='html')
|
|
|
+
|
|
|
+ # Enviar el correo usando SMTP de Gmail
|
|
|
+ with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
|
|
|
+ smtp.login(EMAIL_ORIGEN, CONTRASENA)
|
|
|
+ smtp.send_message(msg)
|
|
|
+
|
|
|
+
|
|
|
def load_bg_data() -> List[Dict[str, str]]:
|
|
|
try:
|
|
|
with open(BG_DATA_PATH, 'r', encoding='utf-8') as f:
|
|
|
@@ -215,6 +286,7 @@ async def printer_order(order: OrderWeb):
|
|
|
try:
|
|
|
printer.print_order(print_order, table)
|
|
|
except:
|
|
|
+ send_email()
|
|
|
return JSONResponse(status_code=424, content={"message": "No se pudo imprimir el Pedido, impresora desconectada"})
|
|
|
if not os.path.exists('logs.csv'):
|
|
|
with open('logs.csv', 'w', newline='') as f:
|