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

WIP: make it so that doing : python download_data.py is all you need … #25

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import argparse
import tempfile
import tarfile
import getpass
import subprocess
import webbrowser


data = {
Expand Down Expand Up @@ -48,7 +51,7 @@ def data_fetch(check_hash=True):
-------
None
"""
wget.download(data["url"])
# wget.download(data["url"])
Comment on lines -51 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure you want to comment this?

filename = os.path.basename(data["url"])

if check_hash:
Expand All @@ -57,9 +60,31 @@ def data_fetch(check_hash=True):
if check_hash_correct(filename, data["encrypted_hash"]):
print("Data verified to be correct.")
else:
print(
raise ValueError(
"There is something wrong with the data. Verify that the expected files are present."
)

print("Decrypting archive.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print("Decrypting archive.")
print(
"Decrypting archive.\n"
"You need a password to open the archive. Please visit "
"https://tiny.cc/ramp_stroke_data_form, fill the form and get the "
"password on the validation page."
)

# Decrypt the data.
retcode = subprocess.call(
['openssl', 'aes-256-cbc', '-md', 'sha256',
'-d', '-a', '-in',
'ATLAS_R2.0_encrypted.tar.gz', '-out', 'ATLAS_R2.0.tar.gz',
'-pass', f'pass:{getpass.getpass("Enter password:")}']
)

if retcode != 0: # decrypt failed
url_form = "https://docs.google.com/forms/d/e/1FAIpQLSclH8padHr9zwdQVx9YY_yeM_4OqD1OQFvYcYpAQKaqC6Vscg/viewform"
print("Decrypting failed due to missing openssl command or invalid password. Opening form"
" for you to get this password.")
webbrowser.open_new_tab(url_form)
return

print("Extracting archive.")
tar = tarfile.open(filename.replace("_encrypted", ""), "r:gz")
tar.extractall("./data")
tar.close()
print("Done.")
return


Expand Down