diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file diff --git a/scripts/download_data.py b/scripts/download_data.py new file mode 100644 index 0000000..8646b06 --- /dev/null +++ b/scripts/download_data.py @@ -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") \ No newline at end of file