Skip to content

Commit

Permalink
Merge pull request #60 from raphaelrpl/master
Browse files Browse the repository at this point in the history
🐛 fix landsat downloader from earth explorer (close #59), :bookmak: prepare to releasse 0.6.1
  • Loading branch information
raphaelrpl authored Apr 4, 2022
2 parents b1e7aff + 98f801e commit 9a1613b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Changes
=======


Version 0.6.1 (2022-04-04)
--------------------------

- Fix Landsat Download data from EarthExplorer (USGS) `59 <https://github.com/brazil-data-cube/bdc-collectors/issues/59>`_.


Version 0.6.0 (2022-03-25)
--------------------------

Expand Down
8 changes: 3 additions & 5 deletions bdc_collectors/usgs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ def login(self, username: str, password: str):
# Get HTML form information
response = self.session.get(_login_url)
# Parse the Login Form and retrieve CSRF_TOKEN and Form Secret
form_secret, csrf_token = self._get_login_html_form_info(response.text)
csrf_token = self._get_login_html_form_info(response.text)

body_data = dict(
username=username,
password=password,
csrf=csrf_token,
__ncforminfo=form_secret
)
# Authenticate the user into request Session and keep it open
_ = self.session.post(_login_url, data=body_data, allow_redirects=True)
Expand All @@ -206,13 +205,12 @@ def authenticated(self):
return bool(eros_sso)

def _get_login_html_form_info(self, html: str):
form_secret = re.findall(r'name="__ncforminfo" value="(.+?)"', html)[0]
csrf_token = re.findall(r'name="csrf" value="(.+?)"', html)[0]

if not form_secret and not csrf_token:
if not csrf_token:
raise RuntimeError('Missing "csrf"/"nc_form" property in login page. Is EarthExplorer online?')

return form_secret, csrf_token
return csrf_token

def download(self, product_id: str, entity_id: str, output: str, link_resolver: Callable[[Any], str] = None) -> str:
"""Download data from USGS Server.
Expand Down
2 changes: 1 addition & 1 deletion bdc_collectors/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

"""Version information for BDC-Collectors."""

__version__ = '0.6.0'
__version__ = '0.6.1'

0 comments on commit 9a1613b

Please sign in to comment.