From c7bc51dee4e7ea8b69f79710e5b80ef55067c3c1 Mon Sep 17 00:00:00 2001 From: Daafip Date: Tue, 16 Apr 2024 10:03:07 +0200 Subject: [PATCH] Couldn't get temp file to work ('only' 30mb) --- src/ewatercycle/_forcings/caravan.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ewatercycle/_forcings/caravan.py b/src/ewatercycle/_forcings/caravan.py index 41c931df..0f7bbbe4 100644 --- a/src/ewatercycle/_forcings/caravan.py +++ b/src/ewatercycle/_forcings/caravan.py @@ -182,7 +182,7 @@ def retrieve( def get_shapefiles(directory: Path, basin_id: str): """Retrieves shapefiles from data 4TU.""" - zip_path = directory / "shapefiles.zip" + zip_path = directory / 'shapefiles.zip' output_path = directory / "shapefiles" shape_path = directory / f"{basin_id}.shp" @@ -192,16 +192,16 @@ def get_shapefiles(directory: Path, basin_id: str): timeout = 300 try: with requests.get(SHAPEFILE_URL, timeout=timeout) as response: - with tempfile.TemporaryFile() as f: - shutil.copyfileobj(response.raw, f) - f.seek(0) - with zipfile.ZipFile(f) as z: - z.extractall(directory) + with zip_path.open('wb') as fin: + fin.write(response.content) except requests.exceptions.Timeout: msg = f"Issue connecting to {SHAPEFILE_URL} after {timeout}s" raise RuntimeError(msg) + with zipfile.ZipFile(zip_path) as myzip: + myzip.extractall(path=directory) + extract_basin_shapefile(basin_id, combined_shapefile_path, shape_path) return shape_path