
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))

[((300, 339), 'requests.get', 'requests.get', (['url'], {'allow_redirects': '(True)'}), '(url, allow_redirects=True)\n', (312, 339), False, 'import requests\n'), ((487, 507), 'os.remove', 'os.remove', (['temp_file'], {}), '(temp_file)\n', (496, 507), False, 'import os\n'), ((98, 123), 'os.path.exists', 'os.path.exists', (['DATA_PATH'], {}), '(DATA_PATH)\n', (112, 123), False, 'import os\n'), ((129, 151), 'os.makedirs', 'os.makedirs', (['DATA_PATH'], {}), '(DATA_PATH)\n', (140, 151), False, 'import os\n'), ((410, 441), 'zipfile.ZipFile', 'zipfile.ZipFile', (['temp_file', '"""r"""'], {}), "(temp_file, 'r')\n", (425, 441), False, 'import zipfile\n'), ((637, 664), 'os.path.exists', 'os.path.exists', (['RESULT_PATH'], {}), '(RESULT_PATH)\n', (651, 664), False, 'import os\n'), ((670, 694), 'os.makedirs', 'os.makedirs', (['RESULT_PATH'], {}), '(RESULT_PATH)\n', (681, 694), False, 'import os\n'), ((585, 627), 'os.path.join', 'os.path.join', (['DATA_PATH', '"""datasets-hn2dct"""'], {}), "(DATA_PATH, 'datasets-hn2dct')\n", (597, 627), False, 'import os\n'), ((738, 766), 'os.path.abspath', 'os.path.abspath', (['RESULT_PATH'], {}), '(RESULT_PATH)\n', (753, 766), False, 'import os\n')]