| import os |
| import zipfile |
| import pandas as pd |
| from config import settings |
|
|
| class ZipExporter: |
| def __init__(self): |
| self.base_dir = settings.DOWNLOAD_DIR |
|
|
| def export_zip(self, metadata_df: pd.DataFrame, output_zip_path: str): |
| """Exports all downloaded files into a single ZIP archive.""" |
| if not os.path.exists(output_zip_path): |
| os.makedirs(output_zip_path, exist_ok=True) |
| |
| print(f"\n๐ฆ Starting ZIP export to: {output_zip_path}") |
| |
| with zipfile.ZipFile(output_zip_path, 'w', zipfile.ZIP_DEFLATED) as zf: |
| |
| for index, row in metadata_df.iterrows(): |
| file_path = row['download_path'] |
| |
| if os.path.exists(file_path): |
| |
| arcname = os.path.relpath(file_path, self.base_dir) |
| zf.write(file_path, arcname) |
| print(f" - Added: {arcname}") |
| else: |
| print(f" - Warning: File missing during zip export: {file_path}") |
| |
| print(f"๐ ZIP Export Complete! Archive saved at: {output_zip_path}") |
| return True |
|
|
| def export_csv(self, metadata_df: pd.DataFrame, output_csv_path: str): |
| """Exports the metadata DataFrame to a CSV file.""" |
| if not metadata_df.empty: |
| metadata_df.to_csv(output_csv_path, index=False) |
| print(f"๐พ CSV Export Complete! Metadata saved to: {output_csv_path}") |
| return True |
| print("โ ๏ธ Metadata DataFrame is empty. CSV export skipped.") |
| return False |
|
|