Skip to content

Commit

Permalink
Add script for downloading data using python
Browse files Browse the repository at this point in the history
  • Loading branch information
finsberg committed Nov 22, 2023
1 parent d70178f commit 73f1db9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions data/download_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import tarfile
from pathlib import Path
import requests # pip install requests
from tqdm import tqdm # pip install tqdm


def download(path, link, desc=None):
if desc is None:
desc = f"Download data to {path}"

response = requests.get(link, stream=True)
total_size_in_bytes = int(response.headers.get("content-length", 0))
progress_bar = tqdm(
total=total_size_in_bytes,
unit="iB",
unit_scale=True,
desc=desc,
)

with open(path, "wb") as handle:
for data in response.iter_content(chunk_size=1000 * 1024):
progress_bar.update(len(data))
handle.write(data)
progress_bar.close()


if __name__ == "__main__":
datafile = Path("data.tar")
download(datafile, "https://www.dropbox.com/s/6bkbw6v269dyfie/data.tar?dl=1")
data = tarfile.TarFile(datafile)
data.extractall()

0 comments on commit 73f1db9

Please sign in to comment.