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

Update README.rst and Add a feature of the bar showing the download progress #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ For example,

Will download the from the `data_structure_ANM218457.tar.gz` file from the `alm-1` dataset.

In case of getting error of "AttributeError: module 'crcnsget' has no attribute 'download'", here is an alternative way to download the dataset.

.. code-block:: console

$ git clone https://github.com/neuromusic/crcnsget.git
$ cd crcnsget
$ pip install -e .
$ crcnsget --username <username> --dataset <path to dataset>

Credits
---------

Expand Down
13 changes: 11 additions & 2 deletions crcnsget/crcnsget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import requests
from tqdm import tqdm

URL = 'https://portal.nersc.gov/project/crcns/download/index.php'

Expand All @@ -16,8 +17,16 @@ def download(datafile,username,password):
with requests.Session() as s:
local_filename = login_data['fn'].split('/')[-1]
r = s.post(URL,data=login_data,stream=True)
with open(local_filename, 'wb') as f:
total_size = int(r.headers.get('Content-Length', 0))

with open(local_filename, 'wb') as f, tqdm(
desc=local_filename,
total=total_size,
unit='B',
unit_scale=True,
unit_divisor=1024) as bar:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
print(local_filename)
bar.update(len(chunk))
print(f"{local_filename} downloaded successfully.")
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ flake8==2.6.0
tox==2.3.1
coverage==4.1
Sphinx==1.4.4
tqdm==4.64.1