import ctypes
import pymysql

# Load the ZKTeco SDK DLL
sdk = ctypes.CDLL(r"C:\Windows\System32\fpslib.dll")

# Initialize the device
try:
    sdk.InitDevice()
    print("Device Initialized")
except AttributeError:
    print("InitDevice function not found. Please check the function name in the DLL.")

# Capture fingerprint (modify with the correct function)
try:
    fingerprint_data = sdk.CaptureFingerprint()  # Modify based on actual SDK function
    if fingerprint_data:
        print("Fingerprint Captured")
    else:
        print("Failed to capture fingerprint")
except AttributeError:
    print("CaptureFingerprint function not found. Please check the function name in the DLL.")

# Store fingerprint data in MySQL
if fingerprint_data:
    conn = pymysql.connect(host='localhost', user='root', password='yourpassword', database='attendance')
    cursor = conn.cursor()
    
    # Insert captured fingerprint data into MySQL
    user_id = input("Enter user ID: ")
    sql = "INSERT INTO users (id, fingerprint_template) VALUES (%s, %s)"
    cursor.execute(sql, (user_id, fingerprint_data))  # Adjust data format if necessary
    conn.commit()
    
    # Close database connection
    cursor.close()
    conn.close()
    print("Fingerprint data stored in MySQL")
