Skip to content

Commit 73f1db9

Browse files
committed
Add script for downloading data using python
1 parent d70178f commit 73f1db9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

data/download_data.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import tarfile
2+
from pathlib import Path
3+
import requests # pip install requests
4+
from tqdm import tqdm # pip install tqdm
5+
6+
7+
def download(path, link, desc=None):
8+
if desc is None:
9+
desc = f"Download data to {path}"
10+
11+
response = requests.get(link, stream=True)
12+
total_size_in_bytes = int(response.headers.get("content-length", 0))
13+
progress_bar = tqdm(
14+
total=total_size_in_bytes,
15+
unit="iB",
16+
unit_scale=True,
17+
desc=desc,
18+
)
19+
20+
with open(path, "wb") as handle:
21+
for data in response.iter_content(chunk_size=1000 * 1024):
22+
progress_bar.update(len(data))
23+
handle.write(data)
24+
progress_bar.close()
25+
26+
27+
if __name__ == "__main__":
28+
datafile = Path("data.tar")
29+
download(datafile, "https://www.dropbox.com/s/6bkbw6v269dyfie/data.tar?dl=1")
30+
data = tarfile.TarFile(datafile)
31+
data.extractall()

0 commit comments

Comments
 (0)