Python: Difference between revisions
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( | 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> |