File size: 1,304 Bytes
42029e4
 
 
 
 
 
 
8c66d1b
42029e4
 
 
8c66d1b
 
42029e4
 
 
 
8c66d1b
 
42029e4
 
8c66d1b
 
 
 
42029e4
 
 
8c66d1b
 
42029e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import annotations
import shutil
import sys
import zipfile
from pathlib import Path
import click
sys.path.insert(0, str(Path(__file__).parent.parent))
from src.utils.logging import setup_logging, get_logger
log = get_logger(__name__)

@click.command()
@click.option('--out-dir', default='data/raw', show_default=True)
@click.option('--sample', default=None, type=int, help='Optional: row sample size')
def main(out_dir: str, sample: int | None) -> None:
    setup_logging()
    out = Path(out_dir)
    out.mkdir(parents=True, exist_ok=True)
    if shutil.which('kaggle') is None:
        log.warning('kaggle CLI not found. Install with `pip install kaggle` and place your kaggle.json in ~/.kaggle/. Skipping download - the loader will fall back to the synthetic generator.')
        return
    import subprocess
    log.info('Downloading wordsforthewise/lending-club from Kaggle...')
    subprocess.run(['kaggle', 'datasets', 'download', '-d', 'wordsforthewise/lending-club', '-p', str(out)], check=True)
    zip_path = next(out.glob('*.zip'))
    log.info(f'Extracting {zip_path}...')
    with zipfile.ZipFile(zip_path) as zf:
        zf.extractall(out)
    zip_path.unlink()
    log.info(f'Done. Files in {out}: {[p.name for p in out.iterdir()]}')
if __name__ == '__main__':
    main()