Started writing script to download ACE files from NNDC site.

This commit is contained in:
Paul Romano 2013-12-12 22:54:42 -05:00
parent 20ae932639
commit d6957a2524

48
data/get_nndc_data.py Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env python
from __future__ import print_function
import tarfile
import urllib2
baseUrl = 'http://www.nndc.bnl.gov/endf/b7.1/aceFiles/'
files = ['ENDF-B-VII.1-neutron-293.6K.tar.gz',
'ENDF-B-VII.1-neutron-300K.tar.gz',
'ENDF-B-VII.1-neutron-900K.tar.gz',
'ENDF-B-VII.1-neutron-1500K.tar.gz',
'ENDF-B-VII.1-tsl.tar.gz']
block_size = 16384
# ==============================================================================
# DOWNLOAD FILES FROM NNDC SITE
filesComplete = []
for f in files:
# Establish connection to URL
url = baseUrl + f
print('Downloading {0}... '.format(f), end='')
req = urllib2.urlopen(url)
# Get file size from header
file_size = int(req.info().getheaders("Content-Length")[0])
downloaded = 0
# Copy file to disk
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='')
filesComplete.append(f)
# ==============================================================================
# EXTRACT FILES FROM TGZ
for f in files:
if not f in filesComplete:
continue
with tarfile.open(f, 'r') as tgz:
tgz.extractall(path='nndc')