from BunnyCDN.Storage import Storage
from datetime import datetime
import os, config, funcs
from PIL import Image 

if __name__ == '__main__':
    print('Starting processing...')

    newDB, newCursor = config.gen_connection()

    newCursor.execute("SELECT hash FROM media WHERE platform='instagram' AND hash IS NOT NULL")
    existing_files = [image[0] for image in newCursor.fetchall()]

    files = os.listdir('storysaver/missing_data/')

    for file in files:
        filePath = os.path.join('storysaver/missing_data/', file)
        file_hash = funcs.calculate_file_hash(filePath)
        
        if file_hash in existing_files:
            print(f'Duplicate file detected. Removing {filePath}...')
            os.rename(filePath, f'storysaver/dupes/{file}')