Skip to content

Commit

Permalink
add progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
PolarBean committed Sep 12, 2024
1 parent f568d65 commit 1fd2290
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import py7zr
from brainglobe_utils.IO.image import load_any
from rich.progress import track
from rich.progress import Progress, track

from brainglobe_atlasapi import BrainGlobeAtlas, utils
from brainglobe_atlasapi.atlas_generation.mesh_utils import (
Expand Down Expand Up @@ -114,15 +114,20 @@ def download_resources():
if not os.path.isdir(
atlas_files_dir / "Multimodal_mouse_brain_atlas_files"
):
"""This is needed to get the source data from their server,
and bypass cloudflare which is only allowing browser access"""
req = urllib.request.Request(ATLAS_FILE_URL, headers=HEADERS)
with (
urllib.request.urlopen(req) as response,
open(destination_path, "wb") as out_file,
):
data = response.read() # a `bytes` object
out_file.write(data)
total = int(response.headers.get("content-length", 0))
with Progress() as progress:
task = progress.add_task("[cyan]Downloading...", total=total)
while not progress.finished:
chunk = response.read(1024)
if not chunk:
break
out_file.write(chunk)
progress.update(task, advance=len(chunk))
with py7zr.SevenZipFile(destination_path, mode="r") as z:
z.extractall(path=atlas_files_dir)
destination_path.unlink()
Expand Down

0 comments on commit 1fd2290

Please sign in to comment.