import uuid
import sys
import os
import argparse
import hashlib
import shutil
from progress.bar import Bar

def argument_parsing():
    parser = argparse.ArgumentParser()
    parser.add_argument("input_folder", help="the folder of your raws", type=str)
    parser.add_argument("output_folder", help="the location of your website", type=str)
    args = parser.parse_args()

    return args.input_folder, args.output_folder

def main():
    input_folder, output_folder = argument_parsing()
    files: list[str] = [os.path.join(input_folder, f) for f in os.listdir(input_folder)]
    files = [f for f in files if os.path.isfile(f)]
    with Bar("copying...", max=len(files)) as bar:
        for file in files:
            with open(file, 'rb') as f:
                image_data = f.read()
                file_extention: str = file.split(".")[-1]
                file_name: str = hashlib.sha256(image_data).hexdigest()
                path: str = os.path.join(output_folder, file_name)
                if not os.path.exists(path):
                    os.makedirs(path)
                    shutil.copy2(file, os.path.join(path, file_name + "." + file_extention))
            bar.next()

if __name__ == "__main__":
    exit(main())