Database Reader - Code

From RoboWiki
Revision as of 17:49, 9 June 2024 by Robot (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Return back to project page: Door camera - Jakub Vojtek

Python code for the Database Reader:

 
import sqlite3

def print_data():
    with sqlite3.connect('database/face_images.db') as conn:
        c = conn.cursor()
        c.execute('SELECT * FROM images')
        rows = c.fetchall()
        for row in rows:
            print(row)

def delete_data_with_no_faces():
    with sqlite3.connect('database/face_images.db') as conn:
        c = conn.cursor()
        c.execute('DELETE FROM images WHERE detected_faces = 0')
        conn.commit()

if __name__ == '__main__':
    print("Data before deletion:")
    print_data()
    
    delete_data_with_no_faces()
    
    print("Data after deletion:")
    print_data()