Advertisement
Guest User

Untitled

a guest
Aug 29th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. for u in uuids:
  2.     url = "https://site.com/%s" % u
  3.     r = requests.get(url, stream=True,  verify=False, allow_redirects=True,auth=(user,password))
  4.     d = r.headers['content-disposition']
  5.     fname = re.findall("filename=\"(.+)\"", d)[0]
  6.    
  7.     if Path(fname).is_file():
  8.         resume_byte_pos = Path(fname).stat().st_size
  9.         resume_header = {'Range': 'bytes=%d-' % resume_byte_pos}
  10.         r.headers.update(resume_header)
  11.         total_size = int(r.headers.get('content-length', 0));
  12.         wrote = 0
  13.         with open(fname, 'ab') as f:
  14.             for data in tqdm_notebook(r.iter_content(block_size), total=math.ceil(total_size//block_size) , unit='KB', unit_scale=True):
  15.                 wrote = wrote  + len(data)
  16.                 f.write(data)
  17.             if total_size != 0 and wrote != total_size:
  18.                 print("ERROR, something went wrong")  
  19.     else:
  20.         resume_header = {'Range': 'bytes=0'}
  21.         r.headers.update(resume_header)
  22.         total_size = int(r.headers.get('content-length', 0));
  23.         wrote = 0
  24.         with open(fname, 'wb') as f:
  25.             for data in tqdm_notebook(r.iter_content(block_size), total=math.ceil(total_size//block_size) , unit='KB', unit_scale=True):
  26.                 wrote = wrote  + len(data)
  27.                 f.write(data)
  28.             if total_size != 0 and wrote != total_size:
  29.                 print("ERROR, something went wrong")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement