pycharmers.utils.download_utils module

pycharmers.utils.download_utils.decide_extension(content_encoding=None, content_type=None, filename=None)[source]

Decide File Extension based on content_encoding and content_type

Parameters
  • content_encoding (str) – The MIME type of the resource or the data.

  • content_type (str) – The Content-Encoding entity header is used to compress the media-type.

  • filename (str) – The filename.

Returns

Starts with “.”

Return type

ext (str)

Examples

>>> from pycharmers.utils import decide_extension
>>> decide_extension(content_encoding="x-gzip", content_type="application/zip")
.gz
>>> decide_extension(content_encoding="image/png", content_type=None)
.png
>>> decide_extension(content_encoding=None, content_type="application/pdf")
.pdf
pycharmers.utils.download_utils.download_file(url, dirname='.', path=None, bar_width=20, verbose=True)[source]

Download a file.

Parameters
  • url (str) – File URL.

  • dirname (str) – The directory where downloaded data will be saved.

  • path (str) – path/to/downloaded_file

  • bar_width (int) – The width of progress bar.

  • verbose (bool) – Whether print verbose or not.

Returns

path/to/downloaded_file

Return type

path (str)

Examples

>>> from pycharmers.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'