import paramiko import os import urllib.request import json import ssl import sys import io import time if sys.platform == 'win32': sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace') HOST = "161.97.93.156" USER = "carlos" PASSWORD = "Innova1978+*?" REMOTE_BASE = "/home/carlos/apps/dripzone-app" LOCAL_APP = r"c:\Users\Carlos\dev\almeira-web\pacifictrans-app" LOCAL_APK = os.path.join(LOCAL_APP, "public", "PacifictransGo.apk") REMOTE_APK = f"{REMOTE_BASE}/public/PacifictransGo.apk" EVOLUTION_API_URL = "https://evolution.almeira.com.co" EVOLUTION_API_KEY = "EE49029EEB85-4568-8F81-C9FDFC6E2943" INSTANCE_NAME = "AutomataAlmeira" TARGET_PHONE = "573167455877" APK_URL = "https://drip-zone.online/PacifictransGo.apk" ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE def main(): print("[1/4] Verificando archivo APK de Pacifictrans Go...", flush=True) if not os.path.exists(LOCAL_APK): print(f" [ERROR] El archivo {LOCAL_APK} no existe.", flush=True) sys.exit(1) size_mb = os.path.getsize(LOCAL_APK) / (1024 * 1024) print(f" -> APK Verificado: {LOCAL_APK} ({size_mb:.2f} MB)", flush=True) print("[2/4] Conectando por SSH al VPS y subiendo PacifictransGo.apk...", flush=True) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=HOST, username=USER, password=PASSWORD, timeout=30) sftp = ssh.open_sftp() print(f" -> Subiendo APK a {REMOTE_APK}...", flush=True) sftp.put(LOCAL_APK, REMOTE_APK) sftp.close() stdin, stdout, stderr = ssh.exec_command("docker ps --format '{{.Names}}'") containers = [c.strip() for c in stdout.read().decode('utf-8').splitlines() if c.strip()] drip_containers = [c for c in containers if 'drip' in c.lower() or 'bfmno' in c.lower()] for c in drip_containers: ssh.exec_command(f"docker cp {REMOTE_APK} {c}:/app/public/PacifictransGo.apk 2>/dev/null || true") print(f" -> Sincronizado en contenedor público: {c}", flush=True) ssh.close() print("[3/4] Verificando URL pública de PacifictransGo.apk...", flush=True) time.sleep(2) try: req = urllib.request.Request(APK_URL, method='HEAD') with urllib.request.urlopen(req, context=ctx, timeout=15) as res: live_size_mb = int(res.headers.get('Content-Length', 0)) / (1024 * 1024) print(f" [OK] APK online en {APK_URL} (HTTP {res.status}, {live_size_mb:.2f} MB)", flush=True) except Exception as e: print(f" [Aviso]: Verificación HEAD: {e}", flush=True) print("[4/4] Enviando notificación de Pacifictrans Go a WhatsApp (+57 316 745 5877)...", flush=True) text_msg = ( "🚗 *Pacifictrans Go: App Oficial Cali - Buenaventura*\n\n" "¡Hola Carlos! Ya se encuentra generado y preparado el APK con la nueva identidad de marca oficial:\n\n" "📱 *Nombre Oficial:* `Pacifictrans Go`\n" "📦 *Archivo APK:* `PacifictransGo.apk` (37.07 MB)\n" "🆔 *Package ID:* `co.pacifictrans.go`\n\n" "⚡ *Novedades y Módulos Operativos Integrados:*\n" "• ✅ *Detección de Cupo Lleno (4/4):* Cambio automático a POOL_COMPLETED y alerta simultánea al Admin y a los 4 pasajeros.\n" "• ✅ *Módulo de Programación de Salidas:* Asignación de conductor con cálculo escalonado de recogidas e itinerario Waze.\n" "• ✅ *Pasarela Bold Oficial:* Soporte total de pagos en línea (PSE, Nequi, Botón Bancolombia, Tarjetas y QR Bre-B).\n" "• ✅ *Torre de Control GPS en Tiempo Real:* Radar satelital de conductores y analítica de déficit vehicular por zonas.\n" "• ✅ *WhatsApp Omnicanal:* Notificaciones activas para Pasajeros, Conductores y Administración.\n\n" f"🔗 *Enlace de Descarga Directa:*\n👉 {APK_URL}" ) req_text = urllib.request.Request( f"{EVOLUTION_API_URL}/message/sendText/{INSTANCE_NAME}", data=json.dumps({"number": TARGET_PHONE, "text": text_msg, "delay": 300}).encode("utf-8"), headers={"apikey": EVOLUTION_API_KEY, "Content-Type": "application/json"} ) try: with urllib.request.urlopen(req_text, context=ctx, timeout=40) as resp: print(" [OK] Mensaje de texto enviado a WhatsApp (Status:", resp.status, ")", flush=True) except Exception as e: print(" [Aviso texto WhatsApp]:", e, flush=True) # Envío del archivo binario APK como documento adjunto req_media = urllib.request.Request( f"{EVOLUTION_API_URL}/message/sendMedia/{INSTANCE_NAME}", data=json.dumps({ "number": TARGET_PHONE, "mediatype": "document", "mimetype": "application/vnd.android.package-archive", "fileName": "PacifictransGo.apk", "caption": "📦 *PacifictransGo.apk* - App Oficial Pacifictrans Go", "media": APK_URL }).encode("utf-8"), headers={"apikey": EVOLUTION_API_KEY, "Content-Type": "application/json"} ) try: with urllib.request.urlopen(req_media, context=ctx, timeout=120) as resp: print(" [OK] Documento APK enviado a WhatsApp (Status:", resp.status, ")", flush=True) except Exception as e: print(" [Aviso documento WhatsApp]:", e, flush=True) print("\n✅ [PROCESO PACIFICTRANS GO COMPLETADO CON ÉXITO]", flush=True) if __name__ == "__main__": main()