@@ -26,19 +26,29 @@ def find_keys(keys,substring):
26
26
class netrunner ():
27
27
""" This class will house all the functions needed to query the GPM FTP"""
28
28
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 ):
30
31
self .servername = servername
31
32
if servername == 'NearRealTime' :
32
33
self .server = 'https://jsimpsonhttps.pps.eosdis.nasa.gov/text'
33
34
elif servername == 'Research' :
34
35
self .server = 'https://arthurhouhttps.pps.eosdis.nasa.gov/text'
35
36
self .s_time = start_time
36
37
self .e_time = end_time
38
+ self .verbose = verbose
39
+
40
+ #check username input
37
41
if username is None :
38
42
print ('Please enter your PPS registered email as the username' )
39
43
else :
40
44
self .username = username
41
45
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
+
42
52
if autorun :
43
53
#this will grab all the files on your day of interest
44
54
self .get_file_list ()
@@ -87,16 +97,23 @@ def get_file(username,filename,server='https://jsimpsonhttps.pps.eosdis.nasa.gov
87
97
""" Some bit of code modified from here:
88
98
https://gpm.nasa.gov/sites/default/files/document_files/PPS-jsimpsonhttps_retrieval.pdf
89
99
"""
100
+
101
+ #Note from dev.: this function is not used... RJC 10/09/22
90
102
url = server + filename
91
- print ('Downloading: {}' .format (url ))
103
+
104
+ if self .verbose :
105
+ print ('Downloading: {}' .format (url ))
106
+
92
107
cmd = 'curl -s -u ' + username + ':' + username + ' ' + url + ' -o ' + \
93
108
os .path .basename (filename )
94
109
args = cmd .split ()
95
110
process = subprocess .Popen (args ,
96
111
stdout = subprocess .PIPE ,
97
112
stderr = subprocess .PIPE )
98
113
process .wait ()
99
- print ('Done' )
114
+
115
+ if self .verbose :
116
+ print ('Done' )
100
117
101
118
def locate_file (self ):
102
119
"""
@@ -180,22 +197,48 @@ def locate_file(self):
180
197
ind_b = np .intersect1d (ind_l ,ind_r )
181
198
self .filename = self .file_list [ind_b ]
182
199
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 )
185
202
ind_b = np .intersect1d (ind_l ,ind_r )
186
203
self .filename = self .file_list [ind_b ]
187
204
188
205
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 )
196
213
args = cmd .split ()
197
214
process = subprocess .Popen (args ,
198
215
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 :
201
244
print ('Done' )
0 commit comments