Skip to content

Commit 64df7ea

Browse files
authored
Merge pull request #21 from dopplerchase/multifile
add multifile down.
2 parents 7d4246d + 09ac338 commit 64df7ea

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

drpy/io/io.py

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,29 @@ def find_keys(keys,substring):
2626
class netrunner():
2727
""" This class will house all the functions needed to query the GPM FTP"""
2828

29-
def __init__(self,servername='NearRealTime',username=None,start_time=None,end_time=None,autorun=True,savedir='./'):
29+
def __init__(self,servername='NearRealTime',username=None,start_time=None,end_time=None,
30+
autorun=True,savedir='./',verbose=True):
3031
self.servername = servername
3132
if servername=='NearRealTime':
3233
self.server ='https://jsimpsonhttps.pps.eosdis.nasa.gov/text'
3334
elif servername=='Research':
3435
self.server = 'https://arthurhouhttps.pps.eosdis.nasa.gov/text'
3536
self.s_time = start_time
3637
self.e_time = end_time
38+
self.verbose = verbose
39+
40+
#check username input
3741
if username is None:
3842
print('Please enter your PPS registered email as the username')
3943
else:
4044
self.username=username
4145

46+
#check dates, multi-day not supported
47+
if self.e_time is not None:
48+
if self.s_time.day != self.e_time.day:
49+
print('More than one day given as input!')
50+
print('Multi-day downloads are not currently supported')
51+
4252
if autorun:
4353
#this will grab all the files on your day of interest
4454
self.get_file_list()
@@ -87,16 +97,23 @@ def get_file(username,filename,server='https://jsimpsonhttps.pps.eosdis.nasa.gov
8797
""" Some bit of code modified from here:
8898
https://gpm.nasa.gov/sites/default/files/document_files/PPS-jsimpsonhttps_retrieval.pdf
8999
"""
100+
101+
#Note from dev.: this function is not used... RJC 10/09/22
90102
url = server + filename
91-
print('Downloading: {}'.format(url))
103+
104+
if self.verbose:
105+
print('Downloading: {}'.format(url))
106+
92107
cmd = 'curl -s -u ' + username+':'+username+' ' + url + ' -o ' + \
93108
os.path.basename(filename)
94109
args = cmd.split()
95110
process = subprocess.Popen(args,
96111
stdout=subprocess.PIPE,
97112
stderr=subprocess.PIPE)
98113
process.wait()
99-
print('Done')
114+
115+
if self.verbose:
116+
print('Done')
100117

101118
def locate_file(self):
102119
"""
@@ -180,22 +197,48 @@ def locate_file(self):
180197
ind_b = np.intersect1d(ind_l,ind_r)
181198
self.filename = self.file_list[ind_b]
182199
else:
183-
ind_l = np.where(dtimes_s >= self.s_time)
184-
ind_r = np.where(dtimes_e <= self.e_time)
200+
ind_l = np.where(dtimes_e >= self.s_time)
201+
ind_r = np.where(dtimes_s <= self.e_time)
185202
ind_b = np.intersect1d(ind_l,ind_r)
186203
self.filename = self.file_list[ind_b]
187204

188205
def download(self,savedir='./'):
189-
if len(self.filename) > 1:
190-
print('Ope: Multiple file downloads not currently supported. Sorry.')
191-
else:
192-
url = self.server + self.filename[0]
193-
print('Downloading: {}'.format(url))
194-
cmd = 'curl -s -u ' + self.username+':'+self.username+' ' + url + ' -o ' + \
195-
os.path.basename(savedir+self.filename[0])
206+
for i,file in enumerate(self.filename):
207+
url = self.server + file
208+
if self.verbose:
209+
print('Downloading {} of {}: {}'.format(i,len(self.filename),url))
210+
211+
cmd = 'curl -u ' + self.username+':'+self.username+' ' + url + ' -o ' + \
212+
os.path.basename(savedir+file)
196213
args = cmd.split()
197214
process = subprocess.Popen(args,
198215
stdout=subprocess.PIPE,
199-
stderr=subprocess.PIPE)
200-
process.wait()
216+
stderr=subprocess.PIPE,
217+
shell=False,
218+
universal_newlines=True)
219+
220+
# outs, errs = process.communicate()
221+
# print(outs,errs)
222+
# process.wait()
223+
if self.verbose:
224+
it = -1
225+
while True:
226+
227+
output = process.stderr.readline()
228+
if output == '' and process.poll() is not None:
229+
break
230+
if output:
231+
if it == -1:
232+
#need to print header
233+
print(output.strip())
234+
it = 0
235+
else:
236+
print(output.strip(),end=' \r',)
237+
238+
rc = process.poll()
239+
else:
240+
process.wait()
241+
242+
243+
if self.verbose:
201244
print('Done')

0 commit comments

Comments
 (0)