Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 357 #358

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [unreleased]
* Fix zero granules being reported for restricted datasets

## [v0.7.1] 2023-11-08
* Bug Fixes:
* Treat granules without `RelatedUrls` as not cloud-hosted.
Expand Down
21 changes: 20 additions & 1 deletion earthaccess/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def hits(self) -> int:


Returns:
number of results reproted by CMR
number of results reported by CMR
"""
return super().hits()

Expand Down Expand Up @@ -318,6 +318,25 @@ def __init__(self, auth: Any = None, *args: Any, **kwargs: Any) -> None:

self._debug = False

def hits(self) -> int:
"""
Returns the number of hits the current query will return. This is done by
making a lightweight query to CMR and inspecting the returned headers.

:returns: number of results reported by CMR
"""

url = self._build_url()

response = self.session.get(url, headers=self.headers, params={"page_size": 0})

try:
response.raise_for_status()
except exceptions.HTTPError as ex:
raise RuntimeError(ex.response.text)

return int(response.headers["CMR-Hits"])

def parameters(self, **kwargs: Any) -> Type[CollectionQuery]:
"""Provide query parameters as keyword arguments. The keyword needs to match the name
of the method, and the value should either be the value or a tuple of values.
Expand Down
Loading