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

Accomodate multiple zip file downloads #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 31 additions & 8 deletions notebooks/Customize and Access NSIDC Data.ipynb
Expand Up @@ -685,14 +685,37 @@
"\n",
" # Download zipped order if status is complete or complete_with_errors\n",
" if status == 'complete' or status == 'complete_with_errors':\n",
" downloadURL = 'https://n5eil02u.ecs.nsidc.org/esir/' + orderID + '.zip'\n",
" print('Zip download URL: ', downloadURL)\n",
" print('Beginning download of zipped output...')\n",
" zip_response = session.get(downloadURL)\n",
" # Raise bad request: Loop will stop for bad response code.\n",
" zip_response.raise_for_status()\n",
" with zipfile.ZipFile(io.BytesIO(zip_response.content)) as z:\n",
" z.extractall(path)\n",
"\n",
" # When the request size is large, zip files will be divided into max 4 files\n",
" multiple_zip_files_flag = 1\n",
" for nzip in range(1,5):\n",
" try:\n",
" downloadURL = 'https://n5eil02u.ecs.nsidc.org/esir/' + orderID + '.zip?' + str(nzip)\n",
" print('Zip download URL: ', downloadURL)\n",
" print('Beginning download of zipped output...')\n",
" zip_response = session.get(downloadURL)\n",
" # Raise bad request: Loop will stop for bad response code.\n",
" zip_response.raise_for_status()\n",
" with zipfile.ZipFile(io.BytesIO(zip_response.content)) as z:\n",
" z.extractall(path)\n",
" except:\n",
" multiple_zip_files_flag = 0\n",
" continue\n",
" \n",
" # When the request size is small, only one zip file will be created\n",
" if multiple_zip_files_flag == 0:\n",
" try: \n",
" downloadURL = 'https://n5eil02u.ecs.nsidc.org/esir/' + orderID + '.zip'\n",
" print('Zip download URL: ', downloadURL)\n",
" print('Beginning download of zipped output...')\n",
" zip_response = session.get(downloadURL)\n",
" # Raise bad request: Loop will stop for bad response code.\n",
" zip_response.raise_for_status()\n",
" with zipfile.ZipFile(io.BytesIO(zip_response.content)) as z:\n",
" z.extractall(path)\n",
" except:\n",
" print('Zip download failed.')\n",
" \n",
" print('Data request', page_val, 'is complete.')\n",
" else: print('Request failed.')\n",
" \n",
Expand Down