def download_(url, dst): """ @param: url to download file @param: dst place to put the file """ file_size = int(urlopen(url).info().get("Content-Length", -1)) if os.path.exists(dst): first_byte = os.path.getsize(dst) else: first_byte = 0 if first_byte >= file_size: return file_size header = {"Range": "bytes=%s-%s" % (first_byte, file_size)} pbar = tqdm( total=file_size, initial=first_byte, unit="B", unit_scale=True, desc=url.split("/")[-1], ) req = requests.get(url, headers=header, stream=True) with (open(get_path_data(dst), "wb")) as f: for chunk in req.iter_content(chunk_size=1024): if chunk: f.write(chunk) pbar.update(1024) pbar.close()
def get_file(name): db = TinyDB(path_db_) temp = Query() if len(db.search(temp.name == name)) > 0: path = get_path_data(db.search(temp.name == name)[0]["file"]) db.close() if not os.path.exists(path): download(name) return path
def get_file(name): db=TinyDB(path_db_) temp = Query() if len(db.search(temp.name==name))>0: path= get_path_data(db.search(temp.name==name)[0]['file']) db.close() if not os.path.exists(path): download(name) return path
def download_(url, dst): """ @param: url to download file @param: dst place to put the file """ file_size = int(urlopen(url).info().get('Content-Length', -1)) if os.path.exists(dst): first_byte = os.path.getsize(dst) else: first_byte = 0 if first_byte >= file_size: return file_size header = {"Range": "bytes=%s-%s" % (first_byte, file_size)} pbar = tqdm( total=file_size, initial=first_byte, unit='B', unit_scale=True, desc=url.split('/')[-1]) req = requests.get(url, headers=header, stream=True) with(open(get_path_data(dst), 'wb')) as f: for chunk in req.iter_content(chunk_size=1024): if chunk: f.write(chunk) pbar.update(1024) pbar.close()