Skip to content

Instantly share code, notes, and snippets.

@yashppawar
Created December 21, 2021 00:21
Show Gist options
  • Save yashppawar/396bfa5281273a673ad88293f5f58c06 to your computer and use it in GitHub Desktop.
Save yashppawar/396bfa5281273a673ad88293f5f58c06 to your computer and use it in GitHub Desktop.
Using python to download files over the internet
import requests
from tqdm import tqdm
def download_file(filename, url):
chunkSize = 1024
r = requests.get(url, stream=True)
with open(filename, 'wb') as f:
pbar = tqdm( unit="B", total=int(r.headers['Content-Length']) )
for chunk in r.iter_content(chunk_size=chunkSize):
if chunk: # filter out keep-alive new chunks
pbar.update(len(chunk))
f.write(chunk)
return filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment