I have written a small program code which automatically downloads something from Kaggle. The whole thing should be downloaded to the folder C:/Users/User/Documents/dataset
. Here is the problem, when I run the code the first time the path is correct. If I run the code again I get the following path C:/Users/User/Documents/dataset/dataset
. The problem is the folder dataset
is added every time the program is executed. What is the reason for this?
I use Jupyter Notebook
under Anaconda
import pathlib
import json
import os
dir_path = ""
dataset_name = "stroke-prediction-dataset"
dir_path = pathlib.Path("").resolve()
save_path = dir_path / "dataset"
# Therefore it also never recognizes this If statement
# because it always creates a new folder
if (save_path / pathlib.Path(dataset_name+".zip")).is_file() == False:
USERNAME_KAGGLE = "..."
TOKEN_KAGGLE = "..."
if not os.path.exists(save_path):
os.makedirs(save_path)
os.chdir(save_path)
# Download the dataset from kaggle
!pip install kaggle
print()
api_token = {"username":USERNAME_KAGGLE,"key":TOKEN_KAGGLE}
with open(os.path.expanduser('~') + '/.kaggle/kaggle.json', 'w') as file:
json.dump(api_token, file)
!kaggle datasets download -d fedesoriano/stroke-prediction-dataset