Fixes for the getanc.py and modis_atteph.py login issues
Posted: Thu Jan 16, 2020 10:39 pm America/New_York
Hi all,I wrote two scripts to work-around the getanc.py and modis_atteph.py login issues. Offered here "as is" under public ___domain license in the hope this helps others. Please post fixes or improvements here for others to benefit.To install them move getanc.py to getanc-real.py and move modis_atteph.py to modis_atteph-real.py and then copy the appropriate script below into getanc.py or modis_atteph.py.the new script will call the realscript with '-d' option to get the filenames, then download those files and move them to where they belong.UPDATED: added support for ozone files in getanc.pyroot@B1B8B6F:/maps/nasa/tmp# cat modis_atteph.py#!/usr/bin/env python3import subprocessimport os.pathimport sysimport osdef fetchAndStore(fname): (fpath, fn) = os.path.split(fname) os.makedirs(fpath, exist_ok=True) url = 'https://oceandata.sci.gsfc.nasa.gov (/cgi/getfile/) ' + fn wget = ['wget', '-q', '--load-cookies', '~/.urs_cookies', '--save-cookies', '~/.urs_cookies', '--auth-no-challenge=on', '--keep-session-cookies', '--content-disposition', url] out = subprocess.run(wget, stdout= subprocess.PIPE, stderr=subprocess.STDOUT) if os.path.exists(fn): mv = ['mv', fn, fname] subprocess.run(mv) elif os.path.exists(fn + '.bz2'): mv = ['mv', fn + '.bz2', fname + '.bz2'] subprocess.run(mv) unzip = ['bunzip2', fname + '.bz2'] subprocess.run(unzip) else: print('ERROR: failed to fetch: ' + url + "\n") print(out.stdout.decode('utf-8'))atteph = '/u/oceandata/scripts/modis_atteph-real.py';cmd = [atteph, '-d'] + sys.argv[1:]out = subprocess.run(cmd, stdout= subprocess.PIPE, stderr=subprocess.STDOUT)lines = out.stdout.decode('utf-8').splitlines()for line in lines: line = line.strip() if "att1=" in line or "att2=" in line or "att3=" in line: attfile = line[5:] print(attfile + "\n") if not os.path.exists(attfile): fetchAndStore(attfile) elif "eph1=" in line or "eph2=" in line or "eph3=" in line: ephfile = line[5:] print(ephfile + "\n") if not os.path.exists(ephfile): fetchAndStore(ephfile)root@B1B8B6F:/u/oceancolor-bin/scripts# cat getanc.py#!/usr/bin/env python3import subprocessimport os.pathimport sysimport osdef fetchAndStore(fname): (fpath, fn) = os.path.split(fname) os.makedirs(fpath, exist_ok=True) url = 'https://oceandata.sci.gsfc.nasa.gov (/cgi/getfile/) ' + fn wget = ['wget', '-q', '--load-cookies', '~/.urs_cookies', '--save-cookies', '~/.urs_cookies', '--auth-no-challenge=on', '--keep-session-cookies', '--content-disposition', url] out = subprocess.run(wget, stdout= subprocess.PIPE, stderr=subprocess.STDOUT) if os.path.exists(fn): mv = ['mv', fn, fname] subprocess.run(mv) elif os.path.exists(fn + '.bz2'): mv = ['mv', fn + '.bz2', fname + '.bz2'] subprocess.run(mv) unzip = ['bunzip2', fname + '.bz2'] subprocess.run(unzip) elif "ozone" in line: ozfile = line[7:] print(ozfile + "\n") if not os.path.exists(ozfile): fetchAndStore(ozfile) else: print('ERROR: failed to fetch: ' + url + "\n") print(out.stdout.decode('utf-8'))getanc = '/u/oceandata/scripts/getanc-real.py';cmd = [getanc, '-d'] + sys.argv[1:]out = subprocess.run(cmd, stdout= subprocess.PIPE, stderr=subprocess.STDOUT)lines = out.stdout.decode('utf-8').splitlines()for line in lines: line = line.strip() if "icefile=" in line: icefile = line[8:] print(icefile + "\n") if not os.path.exists(icefile): fetchAndStore(icefile) elif "met" in line: metfile = line[5:] print(metfile + "\n") if not os.path.exists(metfile): fetchAndStore(metfile) elif "sstfile=" in line: sstfile = line[8:] print(sstfile + "\n") if not os.path.exists(sstfile): fetchAndStore(sstfile)