forked from lisphilar/covid19-sir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.py
44 lines (39 loc) · 1.43 KB
/
input.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
from pathlib import Path
def main():
# Current directory
cwd = Path.cwd()
# The KAGGLE_CONFIG_DIR env var must be setup before loading KaggleApi
if Path("kaggle.json").exists():
os.environ["KAGGLE_CONFIG_DIR"] = cwd + "/"
try:
from kaggle.api.kaggle_api_extended import KaggleApi
except Exception:
# Put your kaggle.json in the directory which has input.py
raise FileNotFoundError(
f"Please save kaggle.json in {os.environ['KAGGLE_CONFIG_DIR']} or ~/.kaggle")
api = KaggleApi()
api.authenticate()
# Remove the saved dataset
top_path = Path(cwd) / "kaggle" / "input"
top_path.mkdir(parents=True, exist_ok=True)
shutil.rmtree(top_path)
# Download Kaggle datasets
kaggle_datasets = [
# author/title
"sudalairajkumar/novel-corona-virus-2019-dataset",
"dgrechka/covid19-global-forecasting-locations-population",
"marcoferrante/covid19-prevention-in-italy",
"hotessy/population-pyramid-2019",
"lisphilar/covid19-dataset-in-japan",
]
for name in kaggle_datasets:
# Files will be saved in sub-directories
dirpath = top_path / name.split("/")[1]
api.dataset_download_files(name, path=dirpath, unzip=True)
print("Datasets were successfully saved in kaggle/input directory.")
if __name__ == "__main__":
main()