Skip to content

Commit

Permalink
Merge pull request #44 from terraref/fix-missing-geostreams
Browse files Browse the repository at this point in the history
Return empty file list if no files found
  • Loading branch information
max-zilla authored Feb 20, 2018
2 parents 3ff13fa + 2d5ed8f commit d767e51
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions terrautils/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ def get_sensor(connection, host, key, sensor, sitename=''):
# if sitename is given, look up id and append to sensor name
if sitename:
s = get_sensor_by_name(None, host, key, sitename)
plotid = s['id']
if not sensor.endswith(')'):
sensor += ' ({})'.format(plotid)
if s:
plotid = s['id']
if not sensor.endswith(')'):
sensor += ' ({})'.format(plotid)
else:
return None

log.debug('full sensor name = %s', sensor)

Expand Down Expand Up @@ -149,25 +152,31 @@ def get_file_listing(connection, host, key, sensor, sitename,
until -- ending time (optional)
"""

files = []

r = get_sensor(connection, host, key, sensor, sitename)
stream_id = r[0]['id']
if r:
stream_id = r[0]['id']

url = '%sapi/geostreams/datapoints' % host
params = { 'key': key, 'stream_id': stream_id }
if since:
params['since'] = since
if until:
params['until'] = until
url = '%sapi/geostreams/datapoints' % host
params = { 'key': key, 'stream_id': stream_id }
if since:
params['since'] = since
if until:
params['until'] = until

r = requests.get(url, params=params)
r.raise_for_status()
datasets = [ds['properties']['source_dataset'] for ds in r.json()]
r = requests.get(url, params=params)
r.raise_for_status()
datasets = [ds['properties']['source_dataset'] for ds in r.json()]


for ds in datasets:
flist = get_files(connection, host, key, ds)
if flist:
files.extend(flist)
else:
log.info("No files found for %s" % sensor+" - "+sitename)

files = []
for ds in datasets:
flist = get_files(connection, host, key, ds)
if flist:
files.extend(flist)
return files


Expand Down

0 comments on commit d767e51

Please sign in to comment.