import sqlite3,json
c=sqlite3.connect('file:/var/lib/sma-data/signals.db?mode=ro',uri=True); c.row_factory=sqlite3.Row
for d in [1,7,14,30]:
rows=c.execute("select source_type,source_platform,source_name,count(*) n from signals where source_type in ('facebook_public','meta_ad') and observed_at >= datetime('now',?) group by source_type,source_platform,source_name",('-'+str(d)+' days',)).fetchall()
print('SIGNALS',d,json.dumps([dict(r) for r in rows],ensure_ascii=False))
try:
rows=c.execute("select * from source_runs where lower(source_name) like '%face%' or lower(source_name) like '%meta%' order by rowid desc limit 20").fetchall()
print('RUNS',json.dumps([dict(r) for r in rows],ensure_ascii=False))
except Exception as e: print('RUN_ERROR',repr(e))
c.close()