import os
import zipfile

def compress_python_files():
    # Obtenez le chemin absolu du dossier 'python' dans le dossier courant
    python_directory = os.path.join(os.getcwd(), 'scripts')

    # Vérifiez si le dossier 'python' existe
    if not os.path.exists(python_directory) or not os.path.isdir(python_directory):
        print("Le dossier 'Python' n'existe pas.")
        return

    # Parcours de tous les fichiers dans le dossier 'python'
    for file_name in os.listdir(python_directory):
        # Vérifiez si le fichier a une extension .py
        if not file_name.endswith('.tot'):
            # Obtenez le chemin complet du fichier
            file_path = os.path.join(python_directory, file_name)
            # Créez un fichier zip avec le même nom que le fichier .py
            zip_file_name = os.path.splitext(file_name)[0] + '.zip'
            zip_file_path = os.path.join(python_directory, zip_file_name)
            with zipfile.ZipFile(zip_file_path, 'w') as zipf:
                # Ajoutez le fichier au fichier zip avec son nom
                zipf.write(file_path, os.path.basename(file_path))
            print(f"Compression de '{file_name}' terminée. Fichier zip créé : '{zip_file_name}'")

    print("Compression des fichiers .py dans 'python' terminée.")

if __name__ == "__main__":
    compress_python_files()
