Skip to content

Instantly share code, notes, and snippets.

@ryul99
Created December 24, 2019 06:39
Show Gist options
  • Save ryul99/ee9667e0d00841393e53526fe409e776 to your computer and use it in GitHub Desktop.
Save ryul99/ee9667e0d00841393e53526fe409e776 to your computer and use it in GitHub Desktop.
download large size file from web
import requests, sys
from tqdm import tqdm
def download_file(url, local_filename):
# NOTE the stream=True parameter below
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in tqdm(r.iter_content(chunk_size=8192)):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
# f.flush()
return local_filename
if __name__ == '__main__':
if len(sys.argv) != 3:
print('Usages: python large_file_downloader.py url filename')
exit(2)
download_file(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment