import sqlite3 conn = sqlite3.connect('/opt/jetson-counter/jetson_counter.db') cur = conn.cursor() cur.execute("SELECT DISTINCT counting_date FROM batches ORDER BY counting_date DESC LIMIT 5") dates = cur.fetchall() print("Dates:", dates) if dates: latest = dates[0][0] cur.execute("SELECT id, counting_date, batch_number, count, start_time, end_time FROM batches WHERE counting_date = ? ORDER BY batch_number ASC", (latest,)) rows = cur.fetchall() for r in rows: print(r) conn.close()