Created
December 21, 2021 00:21
-
-
Save yashppawar/396bfa5281273a673ad88293f5f58c06 to your computer and use it in GitHub Desktop.
Using python to download files over the internet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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