import os
import tarfile
from six.moves import urllib

DOWNLOAD_ROOT = "https://?/"
# os.path.join() join two or more pathname components, inserting '/' as needed
HOUSING_PATH = os.path.join("datasets", "housing")
HOUSING_URL = DOWNLOAD_ROOT + "/housing.tgz"

def fetch_data(url=HOUSING_URL, path=HOUSING_PATH):
    if not os.path.isdir(path):
        os.makedirs(path)
    tgz_path = os.path.join(path, "housing.tgz")
    urllib.request.urlretrieve(url, tgz_path)
    tgz = tarfile.open(tgz_path)
    tgz.extractall(path=housing_path)
    tgz.close()
