# Transfer all UCAC4 files from http://casdc.china-vo.org/mirror/UCAC/UCAC4
import os
import urllib.request

URL_UCAC4 = 'http://casdc.china-vo.org/mirror/UCAC/UCAC4'

# Create the u4b folder if not present
if not os.path.isdir('u4b'):
    os.makedirs('u4b')

# Create the u4i folder if not present
if not os.path.isdir('u4i'):
    os.makedirs('u4i')

# Transfer Index files
print('Transferring file u4index.unf')
urllib.request.urlretrieve(URL_UCAC4 + '/u4i/u4index.unf', 'u4i/u4index.unf')
print('Transferring file zone_stats')
urllib.request.urlretrieve(URL_UCAC4 + '/u4i/zone_stats', 'u4i/zone_stats')

# Transfer data files
for i in range(1, 901):
    curFile = 'z' + '{0:03}'.format(i)
    print('Transferring file ' + curFile)
    urllib.request.urlretrieve(URL_UCAC4 + '/u4b/' + curFile, 'u4b/' + curFile)