#!/bin/env python import os, sys, string, re, time # the EDEX installer prepends to LD_LIBRARY_PATH the path # /lib, where is something like # /awips (the default), /opt/awips, or $HOME/awips. if not os.environ.has_key( "LD_LIBRARY_PATH" ): print "" print "LD_LIBRARY_PATH is not set. Has EDEX been installed?" print "If so, open a new terminal and try again" print "" sys.exit( 1 ) lib_path = "" lib_path_array = os.environ.get("LD_LIBRARY_PATH").split(":") for elem in lib_path_array: if not elem.find("/awips/lib") == -1: lib_path = elem break if len(lib_path) == 0: print "" print "can't find EDEX homedir. Has EDEX been installed?" print "" sys.exit( 1 ) local_edex_sbn_dir = os.path.dirname( lib_path ) local_edex_sbn_dir += "/edex/opt/data/sbn" grib_dir = local_edex_sbn_dir + "/grib" os.chdir(grib_dir) ftp_site="ftp://tgftp.nws.noaa.gov" # # Create the directory time variables from the "last" GMT hour # prevhour = time.strftime("%H", time.gmtime(time.time() - 10800.0)) prevdate = time.strftime("%Y%m%d", time.gmtime(time.time() - 10800.0)) if int(prevhour) > 12 and int(prevhour) <= 18: namhour="12" if int(prevhour) > 18 and int(prevhour) <= 24: namhour="18" if int(prevhour) > 0 and int(prevhour) <= 6: namhour="00" if int(prevhour) > 6 and int(prevhour) <= 12: namhour="06" print "Getting NAM12 files at " + prevhour + "Z" print "On date: " + prevdate # # Get the files # filesToGet = ['fh.0000_tl.press_gr.awp218', 'fh.0006_tl.press_gr.awp218', 'fh.0012_tl.press_gr.awp218', 'fh.0018_tl.press_gr.awp218', 'fh.0024_tl.press_gr.awp218', 'fh.0030_tl.press_gr.awp218', 'fh.0036_tl.press_gr.awp218', 'fh.0042_tl.press_gr.awp218', 'fh.0048_tl.press_gr.awp218', 'fh.0054_tl.press_gr.awp218', 'fh.0060_tl.press_gr.awp218'] for each in filesToGet: try: os.system("wget " + ftp_site + "/SL.us008001/ST.opnl/MT.nam_CY." + namhour + "/RD." + prevdate + "/PT.grid_DF.gr2/" + each + " -O " + each + "." + prevdate + "." + prevhour) except: continue print "files downloaded to the endpoint: " + grib_dir