Created
January 13, 2017 17:35
-
-
Save qhuang872/2a048b6ce715d39d7d4d34d8a9f925fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import urllib.request | |
from urllib.parse import urlparse | |
def download_file(url, cachedir=None, ignorecache=False, filename=None) -> str: | |
"""download_file would create a directory if not exist, then download the file to directory""" | |
if not cachedir: | |
cachedir = os.path.join(os.getcwd(), "build") | |
os.makedirs(cachedir,exit_ok=True) | |
if not filename: | |
filename = os.path.basename(urlparse(url).path) | |
path = os.path.join(cachedir, filename) | |
if ignorecache or not os.path.exists(path): | |
urllib.request.urlretrieve(url, path) | |
return path | |
if __name__ == "__main__": | |
dlpath = download_file("http://pantry.learningequality.org/downloads/ka-lite/0.16/content/contentpacks/en.zip") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment