
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', False, 'import requests\n'), (21, 'os.remove', 'os.remove', False, 'import os\n'), (10, 'os.path.exists', 'os.path.exists', False, 'import os\n'), (11, 'os.makedirs', 'os.makedirs', False, 'import os\n'), (19, 'zipfile.ZipFile', 'zipfile.ZipFile', False, 'import zipfile\n'), (25, 'os.path.exists', 'os.path.exists', False, 'import os\n'), (26, 'os.makedirs', 'os.makedirs', False, 'import os\n'), (23, 'os.path.join', 'os.path.join', False, 'import os\n'), (27, 'os.path.abspath', 'os.path.abspath', False, 'import os\n')]