Skip to content

Commit

Permalink
Couldn't get temp file to work ('only' 30mb)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daafip committed Apr 16, 2024
1 parent 9bad2e0 commit c7bc51d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ewatercycle/_forcings/caravan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down

0 comments on commit c7bc51d

Please sign in to comment.