
import os
import zipfile
import requests


DATA_PATH = './data'
RESULT_PATH = './result'

if not os.path.exists(DATA_PATH):
    os.makedirs(DATA_PATH)

print('Downloading and extracting data...')
url = 'https://weisslab.cs.ucl.ac.uk/WEISSTeaching/datasets/-/archive/hn2dct/datasets-hn2dct.zip' 
r = requests.get(url,allow_redirects=True)
temp_file = 'temp.zip'
_ = open(temp_file,'wb').write(r.content)

with zipfile.ZipFile(temp_file,'r') as zip_obj:
    zip_obj.extractall(DATA_PATH)
os.remove(temp_file)
print('Done.')
print('Head-neck 2D CT data downloaded: %s' % os.path.abspath(os.path.join(DATA_PATH,'datasets-hn2dct')))

if not os.path.exists(RESULT_PATH):
    os.makedirs(RESULT_PATH)
    print('Result directory created: %s' % os.path.abspath(RESULT_PATH))

[(15, 'requests.get', 'requests.get', (['url'], {'allow_redirects': '(True)'}), False, 'import requests\n'), (21, 'os.remove', 'os.remove', (['temp_file'], {}), False, 'import os\n'), (10, 'os.path.exists', 'os.path.exists', (['DATA_PATH'], {}), False, 'import os\n'), (11, 'os.makedirs', 'os.makedirs', (['DATA_PATH'], {}), False, 'import os\n'), (19, 'zipfile.ZipFile', 'zipfile.ZipFile', (['temp_file', '"""r"""'], {}), False, 'import zipfile\n'), (25, 'os.path.exists', 'os.path.exists', (['RESULT_PATH'], {}), False, 'import os\n'), (26, 'os.makedirs', 'os.makedirs', (['RESULT_PATH'], {}), False, 'import os\n'), (23, 'os.path.join', 'os.path.join', (['DATA_PATH', '"""datasets-hn2dct"""'], {}), False, 'import os\n'), (27, 'os.path.abspath', 'os.path.abspath', (['RESULT_PATH'], {}), False, 'import os\n')]