#crear ambiente virtual
#instalar GOES PIP install GOES
#instalar requests pip install requests
#pip install --upgrade GOES 
import GOES
from datetime import datetime, timedelta
import sys
prod = sys.argv[1]
chan = sys.argv[2]
n = datetime.today()
d = n - timedelta(hours=0, minutes=20)
ahora = n.strftime("%Y%m%d-%H%M%S")
desde = d.strftime("%Y%m%d-%H%M%S") 
print('Desde:',desde,'Hasta:',ahora)
##descargar
flist=GOES.download('goes16',prod,DateTimeIni=desde,DateTimeFin=ahora,channel=[chan],path_out='./down/')
print(flist)

if len(flist)==0:
    print('ERROR: No images available....')

import os
newFile = 'ultimo_'+prod+'_'+chan+'.nc'
print('newFile',newFile)
os.rename(flist[-1],'./down/'+newFile) # flist[-1] selecciona el ultimo archivo descargado