File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments