from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED

def main():
    base_dir = Path(__file__).resolve().parent           # .../tensiometreouaga
    parent_dir = base_dir.parent                         # .../Bureau
    folder_name = base_dir.name                          # tensiometreouaga
    out_path = parent_dir / f"{folder_name}.zip"         # .../Bureau/tensiometreouaga.zip

    # Optional excludes (won't be added to the zip)
    EXCLUDE_DIRS = {'.git', '__pycache__'}
    EXCLUDE_FILES = {'zip_it.py'}                        # don't include this script
    EXCLUDE_SUFFIXES = {'.pyc', '.zip'}

    with ZipFile(out_path, 'w', ZIP_DEFLATED) as z:
        for p in base_dir.rglob('*'):
            if p.is_dir():
                # skip ignored directories
                if p.name in EXCLUDE_DIRS:
                    continue
                # no need to add empty dirs explicitly
                continue
            if p.name in EXCLUDE_FILES or p.suffix in EXCLUDE_SUFFIXES:
                continue

            # Keep the folder name as the top-level inside the zip
            arcname = Path(folder_name) / p.relative_to(base_dir)
            z.write(p, arcname)

    print(f"✅ Created: {out_path}")

if __name__ == "__main__":
    main()
