import sqlite3,json,re
c=sqlite3.connect("/home/ultimo/.n8n/database.sqlite")
def q(s,p=()): return c.execute(s,p).fetchall()
print("=== bots + timeout de cada poller ===")
for wfid,nm in [("4457PCm16VZaxvOW","Redator"),("qBWf8H9yx6JkR1or","Dispatcher")]:
    nodes=json.loads(q("SELECT nodes FROM workflow_entity WHERE id=?",(wfid,))[0][0])
    for n in nodes:
        p=json.dumps(n.get("parameters",{}))
        if "getUpdates" in p:
            bot=re.search(r"bot(\d+)",p)
            to=n.get("parameters",{}).get("options",{}).get("timeout")
            print("  ",nm,"| node:",n["name"],"| bot:",(bot.group(1) if bot else "?"),"| timeout:",to)
print("=== dispatcher: últimos 3 min ===")
for r in q("SELECT status,count(*) FROM execution_entity WHERE workflowId=? AND startedAt>datetime(\"now\",\"-3 minutes\") GROUP BY status",("qBWf8H9yx6JkR1or",)):
    print("  ",r[0],r[1])
print("=== hora atual do banco (UTC) ===")
print("  ",q("SELECT datetime(\"now\")")[0][0])
