import sqlite3
# Connect to SQLite database
conn = sqlite3.connect("attendance.db")
cursor = conn.cursor()
# Create table
cursor.execute("""
CREATE TABLE IF NOT EXISTS attendance (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
""")
def log_attendance(name):
cursor.execute("INSERT INTO attendance (name) VALUES (?)", (name,))
conn.commit()
# Update the webcam loop to log attendance
if name not in attendance_log:
attendance_log.add(name)
log_attendance(name)
print(f"{name} marked present in the database!")
Use schedule
to automate the script to run at specific times (e.g., every morning):