def download_file(url, directory='./', local_fname=None, force_write=False):
"""Download the data from source url, unless it's already here.
Args:
filename: string, name of the file in the directory.
work_directory: string, path to working directory.
source_url: url to download from if file doesn't exist.
Returns:
Path to resulting file.
"""
if not os.path.isdir(directory):
os.mkdir(directory)
if local_fname is None:
local_fname = url.split('/')[-1]
local_fname = os.path.join(directory, local_fname)
if os.path.exists(local_fname) and not force_write:
print ("File [{}] existed!".format(local_fname))
return local_fname
print ("Downloading file [{}] from [{}]".format(local_fname, url))
try:
import wget
return wget.download(url, local_fname)
except:
return _single_thread_download(url, local_fname)
评论列表
文章目录