import os, config, funcs

db, cursor = config.gen_connection()

cursor.execute("SELECT phash FROM media WHERE phash IS NOT NULL")
phashes = set([x[0] for x in cursor.fetchall()])

files = funcs.get_files("check_if_exists")

for file in files:
    image_phash = funcs.generate_phash(file)
    
    if image_phash in phashes:
        print(f"File {file} exists in the database")
        os.remove(file)
        
funcs.cleanEmptyFolders("check_if_exists")