tagui.py
def download(download_url = None, filename_to_save = None):
    """function for python 2/3 compatible file download from url"""

    if download_url is None or download_url == '':
        print('[TAGUI][ERROR] - download URL missing for download()')
        return False

    # if not given, use last part of url as filename to save
    if filename_to_save is None or filename_to_save == '':
        download_url_tokens = download_url.split('/')
        filename_to_save = download_url_tokens[-1]

    # delete existing file if exist to ensure freshness
    if os.path.isfile(filename_to_save):
        os.remove(filename_to_save)

    # handle case where url is invalid or has no content
    try:
        if _python2_env():
            import urllib; urllib.urlretrieve(download_url, filename_to_save)
        else:
            import urllib.request; urllib.request.urlretrieve(download_url, filename_to_save)

    except Exception as e:
        print('[TAGUI][ERROR] - failed downloading from ' + download_url + '...')
        print(str(e))
        return False

    # take the existence of downloaded file as success
    if os.path.isfile(filename_to_save):
        return True

    else:
        print('[TAGUI][ERROR] - failed downloading to ' + filename_to_save)
        return False
function for python 2/3 compatible file download from url
function for python 2/3 compatible file download from url
function for python 2 / 3 compatible file download from url
def download(download_url = None, filename_to_save = None):
    if download_url is None or download_url == '':
        print('[TAGUI][ERROR] - download URL missing for download()')
        return False
    if filename_to_save is None or filename_to_save == '':
        download_url_tokens = download_url.split('/')
        filename_to_save = download_url_tokens[-1]
    if os.path.isfile(filename_to_save):
        os.remove(filename_to_save)
    try:
        if _python2_env():
            import urllib; urllib.urlretrieve(download_url, filename_to_save)
        else:
            import urllib.request; urllib.request.urlretrieve(download_url, filename_to_save)
    except Exception as e:
        print('[TAGUI][ERROR] - failed downloading from ' + download_url + '...')
        print(str(e))
        return False
    if os.path.isfile(filename_to_save):
        return True
    else:
        print('[TAGUI][ERROR] - failed downloading to ' + filename_to_save)
        return False
def download ( download_url = None , filename_to_save = None ) : if download_url is None or download_url == '' : print ( '[TAGUI][ERROR] - download URL missing for download()' ) return False if filename_to_save is None or filename_to_save == '' : download_url_tokens = download_url . split ( '/' ) filename_to_save = download_url_tokens [ - 1 ] if os . path . isfile ( filename_to_save ) : os . remove ( filename_to_save ) try : if _python2_env ( ) : import urllib ; urllib . urlretrieve ( download_url , filename_to_save ) else : import urllib . request ; urllib . request . urlretrieve ( download_url , filename_to_save ) except Exception as e : print ( '[TAGUI][ERROR] - failed downloading from ' + download_url + '...' ) print ( str ( e ) ) return False if os . path . isfile ( filename_to_save ) : return True else : print ( '[TAGUI][ERROR] - failed downloading to ' + filename_to_save ) return False
function for python 2/3 compatible file download from url
function for python 2 / 3 compatible file download from url
"""function for python 2/3 compatible file download from url""" # if not given, use last part of url as filename to save # delete existing file if exist to ensure freshness # handle case where url is invalid or has no content # take the existence of downloaded file as success
download_url
filename_to_save