Skip to content

Commit

Permalink
Merge pull request #7 from sjdqbyitr178crs813tgbr8gsdufygeuy53/master
Browse files Browse the repository at this point in the history
Update earthexplorer.py
  • Loading branch information
yannforget authored Aug 5, 2019
2 parents eeeb7ac + 13d7aaa commit 80becb2
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions landsatxplore/earthexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
'LANDSAT_ETM_C1': '12267',
'LANDSAT_8_C1': '12864'
}
SIZES = {
'LANDSAT_TM_C1': 150 * 1024**2,
'LANDSAT_ETM_C1': 235 * 1024**2,
'LANDSAT_8_C1': 919 * 1024**2
}


def _get_tokens(body):
Expand Down Expand Up @@ -76,12 +71,12 @@ def logout(self):
"""Log out from Earth Explorer."""
self.session.get(EE_LOGOUT_URL)

def _download(self, url, output_dir, file_size, chunk_size=1024):
def _download(self, url, output_dir, chunk_size=1024):
"""Download remote file given its URL."""
with tqdm(total=file_size, unit_scale=True, unit='B') as pbar:
with self.session.get(url, stream=True, allow_redirects=True) as r:
local_filename = r.headers['Content-Disposition'].split(
'=')[-1]
with self.session.get(url, stream=True, allow_redirects=True) as r:
file_size = int(r.headers['Content-Length'])
with tqdm(total=file_size, unit_scale=True, unit='B', unit_divisor=1024) as pbar:
local_filename = r.headers['Content-Disposition'].split('=')[-1]
local_filename = os.path.join(output_dir, local_filename)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=chunk_size):
Expand All @@ -98,5 +93,5 @@ def download(self, scene_id, output_dir):
if is_product_id(scene_id):
scene_id = self.api.lookup(dataset, [scene_id], inverse=True)[0]
url = EE_DOWNLOAD_URL.format(folder=EE_FOLDER[dataset], sid=scene_id)
filename = self._download(url, output_dir, file_size=SIZES[dataset])
filename = self._download(url, output_dir)
return filename

0 comments on commit 80becb2

Please sign in to comment.