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

add python script to download the data and unzip them #1

Merged
merged 1 commit into from
Aug 31, 2020
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
42 changes: 42 additions & 0 deletions scripts/download_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import requests
import sys
import zipfile


# Function to download a file through http.get using requests
def download_url(url, save_path):
with open(save_path, "wb") as f:
print("Downloading {} from {}".format(save_path, url))
response = requests.get(url, stream=True)
total_length = response.headers.get('content-length')

if total_length is None: # no content length header
f.write(response.content)
else:
dl = 0
total_length = int(total_length)
for data in response.iter_content(chunk_size=4096):
dl += len(data)
f.write(data)
done = int(50 * dl / total_length)
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) )
sys.stdout.flush()
print()


# Function to unzip files
def unzip_file(path_to_zip_file, directory_to_extract_to):
print("Unzip files..")
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
zip_ref.extractall(directory_to_extract_to)


if __name__ == '__main__':
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/00506/casas-dataset.zip"
url_test = "https://archive.ics.uci.edu/ml/machine-learning-databases/00405/Postures.zip" # Smaller zip to test
save_path = "../data/casas-dataset.zip"
# Download zip file
download_url(url, save_path)
# Unzip it
unzip_file(save_path, "../data_test/")
print("Done")