import time
import shlex, subprocess

str1 = '"https://madis-data.noaa.gov/cgi-bin/textXmlRqt?rdr=https%3A%2F%2Fpublic_madis_public%3Apppppp%40madis-data.noaa.gov%2FmadisPublic1%2Fcgi-bin%2FmadisXmlPublicDir%3F&time='
str2 = '&minbck=-60&minfwd=0&recwin=4&dfltrsel=1&state=AK&latll=32&lonll=-103&latur=41&lonur=-92.38&stanam=&stasel=0&pvdrsel=0&varsel=1&qcsel=1&xml=3&csvmiss=0&nvars=RH&nvars=P&nvars=T&nvars=DD&nvars=FF&nvars=FF15M&nvars=WMOID&nvars=ELEV&nvars=LAT&nvars=LON&nvars=PCP5M&nvars=PCP15M&nvars=PCP1H&nvars=PCPRATE&nvars=PCPINT&nvars=PCPTYPE&nvars=FFGUST&nvars=FSRDINS&nvars=FSRD5M&nvars=FSRD15M&nvars=FSRD1H&nvars=DSRDINS&nvars=DSRD5M&nvars=DSRD15M&nvars=DSRD1H&nvars=BATVLT&nvars=BATVLT2&nvars=PRESWEA&nvars=SKYCOV&nvars=STALOC"'

days = ['01']
times = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', \
         '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', \
         '22', '23']
for i in days:
    for j in times:
        date = '201207' + i + '_' + j + '00'
        #date = '201206' + i + '_' + j + '00'
        print date
        cmd = '/usr/bin/wget wait_retry =5 -O "'
        cmd += date + '.txt" '
        cmd += str1
        cmd += date
        cmd += str2
        args = shlex.split(cmd)
        t1 = time.time()
        p = subprocess.Popen(args)
        t2 = time.time()
        time.sleep(120 - (t2 - t1)) #Wait 2 min
