#import m2m

import time
from m2m.m2mcli import download_hv
import m2m
import config
username = config.USERNAME
password = config.PASSWORD

#HPC
#endpoint_url = 'http://10.165.226.119:7848'
#windows/vm
#endpoint_url = 'http://lsdslb.cr.usgs.gov:7848'


for h, v in [(16,6)]:
    # outroot = f'/some/path/to/c2ard/{h:03}{v:03}'
    # download_hv(username, password, h, v, region, ceph, endpoint_url, aws_profile, outroot, resume, cpu, batch_size)
    print(f'Downloading {h} {v}')
    
    outroot = f'/caldera/projects/usgs/eros/urban_heat_islands/Phase3/hv_downloads/{h:03}{v:03}'

    download_hv(username, password, h, v,
        region = 'CU', ceph=False, endpoint_url=None, aws_profile=None,
        outroot = outroot, resume=False, cpu=1, batch_size=100)
    
    #^^creates a manifest.json file

    # c = 0
    # while True:
    #   try:
    #     # download_hv(username, password, h, v,
    #     # region='CU', ceph=True, endpoint_url=endpoint_url, aws_profile='ceph',
    #     # outroot='/', resume=True, cpu=5, batch_size=100)
    #     download_hv(username, password, h, v,
    #     region='CU', ceph=False, endpoint_url=None, aws_profile=None,
    #     outroot='/caldera/projects/usgs/eros/urban_heat_islands/Phase3/rezatemp/', resume=False, cpu=1, batch_size=100)
    #     break
    #   except Exception as e:
    #     print(e)
    #     c += 1
    #     time.sleep(30)
    #     print(f'Retry {c}')
    #     continue
    # download_hv(username, password, h, v, 'CU', outroot, True, 5, 100)
