Skip to content

Commit

Permalink
Merge pull request #1 from sdevenes/data_downloading
Browse files Browse the repository at this point in the history
add python script to download the data and unzip them
  • Loading branch information
spanoamara authored Aug 31, 2020
2 parents cb13ab8 + 9ce38ed commit b9e055a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
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")

0 comments on commit b9e055a

Please sign in to comment.