Jump to content

Python: Difference between revisions

91 bytes added ,  26 February 2020
Line 219: Line 219:
         folder = os.getcwd()
         folder = os.getcwd()
     full_path = path.join(folder, filename)
     full_path = path.join(folder, filename)
    temp_path = path.join(folder, str(uuid.uuid4()))
     with requests.get(url, stream=True) as r:
     with requests.get(url, stream=True) as r:
         r.raise_for_status()
         r.raise_for_status()
         with open(full_path, 'wb') as f:
         with open(temp_path, 'wb') as f:
             for chunk in r.iter_content(chunk_size=8192):
             for chunk in r.iter_content(chunk_size=8192):
                 if chunk:
                 if chunk:
                     f.write(chunk)
                     f.write(chunk)
    shutil.move(temp_path, full_path)
     return full_path
     return full_path
</syntaxhighlight>
</syntaxhighlight>