veditor.utils.download_utils module¶
- veditor.utils.download_utils.progress_reporthook_create(filename: str = '', bar_width: int = 20, verbose: bool = True) → Callable[[int, int, int], None][source]¶
Create Progress reporthook for
urllib.request.urlretrieve
- Parameters
filename (str, optional) – A downloading filename. Defaults to
""
.bar_width (int, optional) – The maximum width of progress bar.. Defaults to
20
.verbose (bool, optional) – Whether to show progress or not.
- Returns
The
reporthook
which is a callable that accepts ablock number
, aread size
, and thetotal file size
of the URL target.- Return type
Callable[[int,int,int],None]
Examples
>>> import urllib >>> from veditor.utils import progress_reporthook_create >>> urllib.request.urlretrieve(url="hoge.zip", filename="hoge.zip", reporthook=progress_reporthook_create(filename="hoge.zip")) hoge.zip 1.5%[--------------------] 21.5[s] 8.0[GB/s] eta 1415.1[s]
- veditor.utils.download_utils.download_file(url: str, dirname: str = '.', filename: Optional[str] = None, bar_width: int = 20, verbose: bool = True) → str[source]¶
Download a file from
url
- Parameters
url (str) – URL where the data is located.
dirname (str, optional) – The directory where downloaded data will be saved.. Defaults to
"."
.filename (Optional[str], optional) – The name of the file you want to download. Saved with this name. Defaults to
None
.bar_width (int, optional) – The maximum width of progress bar. Defaults to
20
.verbose (bool, optional) – Whether to show progress or not. Defaults to
True
.
- Returns
The path to a downloaded file.
- Return type
str
Examples
>>> from veditor.utils import download_file >>> download_file(url="https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_eye.xml") Download a file from https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_eye.xml * Content-Encoding : None * Content-Length : (333.404296875, 'MB') * Content-Type : text/plain; charset=utf-8 * Save Destination : ./haarcascade_eye.xml haarcascade_eye.xml 100.0%[####################] 0.1[s] 5.5[GB/s] eta -0.0[s] './haarcascade_eye.xml'