AceScottie

python downloader

Mar 17th, 2020
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. self.tmpdir = tempfile.mkdtemp()
  2. with open(self.tmpdir+"\\"+fname, 'wb') as f:
  3.     response = requests.get(url, stream=True)
  4.     total = response.headers.get('content-length')
  5.     if total is None:
  6.         f.write(response.content)
  7.     else:
  8.         downloaded = 0
  9.         total = int(total)
  10.         for data in response.iter_content(chunk_size=max(int(total/1000), 1024*1024)):
  11.             downloaded += len(data)
  12.             f.write(data)
Add Comment
Please, Sign In to add comment