import paramiko
import sys

HOST = "135.125.102.180"
USER = "ubuntu"
PASS = "BotPascal2026!"
REMOTE_BASE = "/var/www/html/repondeur_mail_grok"

def main():
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(HOST, username=USER, password=PASS)
        
        print("--- LOGS ---")
        stdin, stdout, stderr = ssh.exec_command(f"ls -lt {REMOTE_BASE}/data/logs | head -n 5")
        print(stdout.read().decode())
        
        print("--- LATEST LOG CONTENT ---")
        # Find latest log
        stdin, stdout, stderr = ssh.exec_command(f"ls -1t {REMOTE_BASE}/data/logs | head -n 1")
        latest_log = stdout.read().decode().strip()
        if latest_log:
            stdin, stdout, stderr = ssh.exec_command(f"tail -n 20 {REMOTE_BASE}/data/logs/{latest_log}")
            print(stdout.read().decode())
            
        print("--- QUEUE.CSV HEADER ---")
        stdin, stdout, stderr = ssh.exec_command(f"head -n 2 {REMOTE_BASE}/data/queue.csv")
        print(stdout.read().decode())
        
        ssh.close()
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()
