
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, 4, 15, 42), 'requests.get', 'requests.get', (), '', False, 'import requests\n'), ((21, 0, 21, 20), 'os.remove', 'os.remove', ({(21, 10, 21, 19): 'temp_file'}, {}), '(temp_file)', False, 'import os\n'), ((10, 7, 10, 32), 'os.path.exists', 'os.path.exists', ({(10, 22, 10, 31): 'DATA_PATH'}, {}), '(DATA_PATH)', False, 'import os\n'), ((11, 4, 11, 26), 'os.makedirs', 'os.makedirs', ({(11, 16, 11, 25): 'DATA_PATH'}, {}), '(DATA_PATH)', False, 'import os\n'), ((19, 5, 19, 35), 'zipfile.ZipFile', 'zipfile.ZipFile', ({(19, 21, 19, 30): 'temp_file', (19, 31, 19, 34): '"""r"""'}, {}), "(temp_file, 'r')", False, 'import zipfile\n'), ((25, 7, 25, 34), 'os.path.exists', 'os.path.exists', ({(25, 22, 25, 33): 'RESULT_PATH'}, {}), '(RESULT_PATH)', False, 'import os\n'), ((26, 4, 26, 28), 'os.makedirs', 'os.makedirs', ({(26, 16, 26, 27): 'RESULT_PATH'}, {}), '(RESULT_PATH)', False, 'import os\n'), ((23, 62, 23, 103), 'os.path.join', 'os.path.join', ({(23, 75, 23, 84): 'DATA_PATH', (23, 85, 23, 102): '"""datasets-hn2dct"""'}, {}), "(DATA_PATH, 'datasets-hn2dct')", False, 'import os\n'), ((27, 43, 27, 71), 'os.path.abspath', 'os.path.abspath', ({(27, 59, 27, 70): 'RESULT_PATH'}, {}), '(RESULT_PATH)', False, 'import os\n')]