try:
from tqdm import tqdm
showtqdm = True
except:
showtqdm = False
def download_bigfile(self,url, filename, target_path, filelists=[]):
'''
Download Big file, use fragment download
'''
r = requests.get(url, stream=True)
content_size = int(r.headers['Content-Length']) / 1024 / 1024
with open(filename, "wb") as f:
print "download file {}, total size: {}M".format(filename, content_size)
if showtqdm:
for chunk in tqdm(iterable=r.iter_content(chunk_size=1024), total=content_size, unit='M'):
if chunk:
f.write(chunk)
else:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)