Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
#71, fixed fetching multiple json files response (splitted request, w…
Browse files Browse the repository at this point in the history
…ith offset and limit) from ESGF search service
  • Loading branch information
Krzysztof (Chris) Bernat authored and kbernat committed Dec 9, 2016
1 parent 5e3e6ea commit a88a8e8
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions cate/ds/esa_cci_odp.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ def _fetch_solr_json(base_url, query_args, offset=0, limit=10000, timeout=10):
"""
Return JSON value read from paginated Solr web-service.
"""
new_offset = offset
combined_json_dict = None
combined_num_found = 0
while True:
paging_query_args = dict(query_args or {})
paging_query_args.update(offset=new_offset, limit=limit, format='application/solr+json')
paging_query_args.update(offset=offset, limit=limit, format='application/solr+json')
url = base_url + '?' + urllib.parse.urlencode(paging_query_args)
with urllib.request.urlopen(url, timeout=timeout) as response:
json_text = response.read()
Expand All @@ -116,15 +114,13 @@ def _fetch_solr_json(base_url, query_args, offset=0, limit=10000, timeout=10):
if num_found < limit:
break
else:
if num_found > 0:
combined_num_found += num_found
docs = json_dict.get('response', {}).get('docs', [])
combined_json_dict.get('response', {}).get('docs', []).append(docs)
combined_json_dict.get('response', {})['numFound'] = combined_num_found
if num_found < limit:
docs = json_dict.get('response', {}).get('docs', [])
combined_json_dict.get('response', {}).get('docs', []).extend(docs)
if num_found < offset + limit:
break
else:
break
offset += limit
return combined_json_dict


Expand Down

0 comments on commit a88a8e8

Please sign in to comment.