from astropy.table import Table
import os

url_list = open('/u/vgorad/work/Data/speclists/lamost_speclist_download.txt', 'r') 
lines = url_list.readlines() 
for line in lines[:-1]:
   dir_path = line.replace('\n', '').replace('http://dr5.lamost.org/v3/sas/fits/', '')
   dir_path = os.path.dirname(os.path.abspath(dir_path))
   try:
      os.makedirs(dir_path)
   except OSError:
      pass
   #dir_path = dir_path.replace('/spectra/','')
   f = open(os.path.join(dir_path, 'urls.txt'), 'a+')
   f.write(line)
   f.close()
   f = open('out_dirs.txt', 'a+')
   f.write(dir_path+'\n')
   f.close()


