import urllib import urllib.request from tqdm import tqdm class DownloadProgressBar(tqdm): def update_to(self, b=1, bsize=1, tsize=None): if tsize is not None: self.total = tsize self.update(b * bsize - self.n) def download_url(url, output_path): with DownloadProgressBar(unit='B', unit_scale=True, miniters=1, desc=url.split('/')[-1]) as t: opener = urllib.request.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] urllib.request.install_opener(opener) urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
Devamını Oku »python file to base64
def file_to_base64(file_path: str) -> str: with open(file_path, "rb") as binnary_file: encoded_string = base64.b64encode(binnary_file.read()) return encoded_string.decode('utf-8')
Devamını Oku »