import sqlite3
c=sqlite3.connect("/home/ultimo/.n8n/database.sqlite")
def q(s,p=()): return c.execute(s,p).fetchall()
sd=q("SELECT staticData FROM workflow_entity WHERE id=?",("qBWf8H9yx6JkR1or",))[0][0]
print("staticData dispatcher:", sd)
print("=== insta (R1zn1l8zDaVpFSkm) - últimas 5 execuções ===")
r=q("SELECT substr(startedAt,1,19),status FROM execution_entity WHERE workflowId=? ORDER BY id DESC LIMIT 5",("R1zn1l8zDaVpFSkm",))
print("\n".join("  "+a+" "+b for a,b in r) if r else "  NENHUMA execução")
print("=== execuções na última hora (todos os workflows) ===")
for a,b,n in q("SELECT w.name,e.status,count(*) FROM execution_entity e JOIN workflow_entity w ON w.id=e.workflowId WHERE e.startedAt>datetime(\"now\",\"-60 minutes\") GROUP BY w.name,e.status ORDER BY w.name",()):
    print("  ",a,"|",b,"|",n)
