Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tqdm import tqdm
- import requests
- import math
- import re
- #hardcoded credentials
- user = 'username'
- password = 'password'
- #build a list of file IDs from a separately-constructed pandas dataframe
- filelist = [0,1,2,3]
- uuids = []
- for i in filelist:
- uuids.append(filedf.iloc[i]['uuid'])
- #Serially retrieve and store the file corresponding to each id
- for u in uuids:
- url = "url/%s" % u
- # Streaming, so we can iterate over the response.
- r = requests.get(url, stream=True,auth=(user,password))
- # Total size in bytes.
- total_size = int(r.headers.get('content-length', 0));
- block_size = 1024
- wrote = 0
- #retrieve the filename from from HTTP headers:
- d = r.headers['content-disposition']
- fname = re.findall("filename=\"(.+)\"", d)[0]
- with open(fname, 'wb') as f:
- for data in tqdm_notebook(r.iter_content(block_size), total=math.ceil(total_size//block_size) , unit='KB', unit_scale=True):
- wrote = wrote + len(data)
- f.write(data)
- if total_size != 0 and wrote != total_size:
- print("ERROR, something went wrong")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement