From 1d01c5f9cf1f7aa4c74fc82ba61649f7bb1a9724 Mon Sep 17 00:00:00 2001 From: Alex Yi Date: Thu, 1 Nov 2018 19:12:25 -0700 Subject: [PATCH] configured for Python3. Added multiple ways to add filename. Added print to notify user if flight name was incorrect. --- .../main/resources/bin/RetrieveAVRISNGData.py | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/crawler/src/main/resources/bin/RetrieveAVRISNGData.py b/crawler/src/main/resources/bin/RetrieveAVRISNGData.py index bb061b0..3cd4491 100644 --- a/crawler/src/main/resources/bin/RetrieveAVRISNGData.py +++ b/crawler/src/main/resources/bin/RetrieveAVRISNGData.py @@ -18,30 +18,38 @@ def handleDownload(block): file.write(block) - print ".", + print (".") -ddir='/Users/alexahuerta/Documents' # set to local path where you want files downloaded to + +ddir='/Users/Alex/Documents' # set to local path where you want files downloaded to os.chdir(ddir) ftp = FTP('avng.jpl.nasa.gov') -print 'Logging in.' +print ('Logging in.') ftp.login() directory = '/' -flight_line = raw_input("Enter name of flight line you wish to download: ") +#if flight name is not included in the command, prompt it +if len(sys.argv) < 2: + flight_line = input("Enter name of flight line you wish to download: ") +else: + flight_line = sys.argv[1] + data2014 = '/AVNG_2014_data_distribution/L2/' data2015 = '/AVNG_2015_data_distribution/L2/' +exists = False ftp.cwd(data2015) dirnames2015 = ftp.nlst() for dirname in dirnames2015: if dirname == flight_line: - print 'Changing to ' + dirname + exists = True + print ('Changing to ' + dirname) ftp.cwd(dirname) filenames = ftp.nlst() # get list of filenames in directory - print filenames + print (filenames) localpath = ddir + '/' + dirname - print localpath + print (localpath) os.mkdir(localpath) # create this directory locally #download each file to the newly created local directory for filename in filenames: @@ -55,12 +63,13 @@ def handleDownload(block): dirnames2014 = ftp.nlst() for dirname in dirnames2014: if dirname == flight_line: - print 'Changing to ' + dirname + exists = True + print ('Changing to ' + dirname) ftp.cwd(dirname) filenames = ftp.nlst() # get list of filenames in directory - print filenames + print (filenames) localpath = ddir + '/' + dirname - print localpath + print (localpath) os.mkdir(localpath) # create this directory locally #download each file to the newly created local directory for filename in filenames: @@ -70,4 +79,6 @@ def handleDownload(block): file.close() ftp.cwd('../..') +if exists == False: + print('Could not locate file: ' + flight_line) ftp.quit()