def download_file(url, filename, sourceiss3bucket=None):
    '\nDownload the file from `url` and save it locally under `filename`.\n    :rtype : bool\n    :param url:\n    :param filename:\n    :param sourceiss3bucket:\n    '
    conn = None
    if sourceiss3bucket:
        bucket_name = url.split('/')[3]
        key_name = '/'.join(url.split('/')[4:])
        try:
            conn = boto.connect_s3()
            bucket = conn.get_bucket(bucket_name)
            key = bucket.get_key(key_name)
            key.get_contents_to_filename(filename=filename)
        except (NameError, BotoClientError):
            try:
                bucket_name = url.split('/')[2].split('.')[0]
                key_name = '/'.join(url.split('/')[3:])
                bucket = conn.get_bucket(bucket_name)
                key = bucket.get_key(key_name)
                key.get_contents_to_filename(filename=filename)
            except Exception as exc:
                raise SystemError('Unable to download file from S3 bucket.\nurl = {0}\nbucket = {1}\nkey = {2}\nfile = {3}\nException: {4}'.format(url, bucket_name, key_name, filename, exc))
        except Exception as exc:
            raise SystemError('Unable to download file from S3 bucket.\nurl = {0}\nbucket = {1}\nkey = {2}\nfile = {3}\nException: {4}'.format(url, bucket_name, key_name, filename, exc))
        print('Downloaded file from S3 bucket -- \n    url      = {0}\n    filename = {1}'.format(url, filename))
    else:
        try:
            response = urllib2.urlopen(url)
            with open(filename, 'wb') as outfile:
                shutil.copyfileobj(response, outfile)
        except Exception as exc:
            raise SystemError('Unable to download file from web server.\nurl = {0}\nfilename = {1}\nException: {2}'.format(url, filename, exc))
        print('Downloaded file from web server -- \n    url      = {0}\n    filename = {1}'.format(url, filename))
    return True
Download the file from `url` and save it locally under `filename`.
    :rtype : bool
    :param url:
    :param filename:
    :param sourceiss3bucket:
def download_file(url, filename, sourceiss3bucket=None):
    '\nDownload the file from `url` and save it locally under `filename`.\n    :rtype : bool\n    :param url:\n    :param filename:\n    :param sourceiss3bucket:\n    '
    conn = None
    if sourceiss3bucket:
        bucket_name = url.split('/')[3]
        key_name = '/'.join(url.split('/')[4:])
        try:
            conn = boto.connect_s3()
            bucket = conn.get_bucket(bucket_name)
            key = bucket.get_key(key_name)
            key.get_contents_to_filename(filename=filename)
        except (NameError, BotoClientError):
            try:
                bucket_name = url.split('/')[2].split('.')[0]
                key_name = '/'.join(url.split('/')[3:])
                bucket = conn.get_bucket(bucket_name)
                key = bucket.get_key(key_name)
                key.get_contents_to_filename(filename=filename)
            except Exception as exc:
                raise SystemError('Unable to download file from S3 bucket.\nurl = {0}\nbucket = {1}\nkey = {2}\nfile = {3}\nException: {4}'.format(url, bucket_name, key_name, filename, exc))
        except Exception as exc:
            raise SystemError('Unable to download file from S3 bucket.\nurl = {0}\nbucket = {1}\nkey = {2}\nfile = {3}\nException: {4}'.format(url, bucket_name, key_name, filename, exc))
        print('Downloaded file from S3 bucket -- \n    url      = {0}\n    filename = {1}'.format(url, filename))
    else:
        try:
            response = urllib2.urlopen(url)
            with open(filename, 'wb') as outfile:
                shutil.copyfileobj(response, outfile)
        except Exception as exc:
            raise SystemError('Unable to download file from web server.\nurl = {0}\nfilename = {1}\nException: {2}'.format(url, filename, exc))
        print('Downloaded file from web server -- \n    url      = {0}\n    filename = {1}'.format(url, filename))
    return True