Address @paulromano comments in #1023

This commit is contained in:
amandalund 2018-07-05 23:25:42 -05:00
parent 7dcd6239eb
commit 4ebeb737ab
11 changed files with 95 additions and 70 deletions

View file

@ -54,10 +54,7 @@ for f in files:
req = urlopen(url)
# Get file size from header
if sys.version_info[0] < 3:
file_size = int(req.info().getheaders('Content-Length')[0])
else:
file_size = req.length
file_size = req.length
downloaded = 0
# Check if file already downloaded

View file

@ -12,8 +12,7 @@ import shutil
import zipfile
import argparse
from io import BytesIO
import requests
from urllib.request import urlopen
import openmc.data
@ -32,6 +31,7 @@ args = parser.parse_args()
base_url = 'http://www.nndc.bnl.gov/endf/b7.1/zips/'
files = ['ENDF-B-VII.1-photoat.zip', 'ENDF-B-VII.1-atomic_relax.zip']
block_size = 16384
# ==============================================================================
# DOWNLOAD FILES FROM NNDC SITE
@ -39,13 +39,44 @@ files = ['ENDF-B-VII.1-photoat.zip', 'ENDF-B-VII.1-atomic_relax.zip']
if not os.path.exists('photon_hdf5'):
os.mkdir('photon_hdf5')
for f in files:
# Establish connection to URL
print('Downloading {}...'.format(f))
url = base_url + f
r = requests.get(url, stream=True)
zipfile.ZipFile(BytesIO(r.content)).extractall()
req = urlopen(url)
# Get file size from header
file_size = req.length
downloaded = 0
# Check if file already downloaded
if os.path.exists(f):
if os.path.getsize(f) == file_size:
print('Skipping ' + f)
continue
else:
overwrite = input('Overwrite {}? ([y]/n) '.format(f))
if overwrite.lower().startswith('n'):
continue
# Copy file to disk
print('Downloading {}... '.format(f), end='')
with open(f, 'wb') as fh:
while True:
chunk = req.read(block_size)
if not chunk: break
fh.write(chunk)
downloaded += len(chunk)
status = '{0:10} [{1:3.2f}%]'.format(
downloaded, downloaded * 100. / file_size)
print(status + chr(8)*len(status), end='')
print('')
# ==============================================================================
# EXTRACT FILES
for f in files:
print('Extracting {0}...'.format(f))
zipfile.ZipFile(f).extractall()
# ==============================================================================
# GENERATE HDF5 DATA LIBRARY

View file

@ -20,10 +20,7 @@ block_size = 16384
req = urlopen(base_url + filename)
# Get file size from header
if sys.version_info[0] < 3:
file_size = int(req.info().getheaders('Content-Length')[0])
else:
file_size = req.length
file_size = req.length
downloaded = 0
# Check if file already downloaded