-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_data.py
More file actions
53 lines (41 loc) · 1.44 KB
/
Copy pathsetup_data.py
File metadata and controls
53 lines (41 loc) · 1.44 KB
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
45
46
47
48
49
50
51
52
53
"""
setup_data.py
-------------
Downloads and extracts the Kaggle dataset automatically.
Requires kaggle API credentials (~/.kaggle/kaggle.json).
Get your token from: https://www.kaggle.com/settings -> API -> Create New Token
Place kaggle.json at C:\\Users\\<you>\\.kaggle\\kaggle.json
"""
import os
import zipfile
import subprocess
import sys
DATASET = "clmentbisaillon/fake-and-real-news-dataset"
DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
def download():
os.makedirs(DATA_DIR, exist_ok=True)
print("Downloading dataset from Kaggle…")
result = subprocess.run(
[sys.executable, "-m", "kaggle", "datasets", "download",
"-d", DATASET, "-p", DATA_DIR],
capture_output=True, text=True
)
if result.returncode != 0:
print("ERROR:", result.stderr)
print("\nMake sure kaggle is installed and your API key is set up.")
print(" pip install kaggle")
print(" Place kaggle.json at ~/.kaggle/kaggle.json")
sys.exit(1)
print(result.stdout)
# Unzip
zip_path = os.path.join(DATA_DIR, "fake-and-real-news-dataset.zip")
if os.path.exists(zip_path):
print("Extracting…")
with zipfile.ZipFile(zip_path, "r") as z:
z.extractall(DATA_DIR)
os.remove(zip_path)
print(f"Done. Files saved to {DATA_DIR}/")
else:
print("Zip not found — check if download succeeded.")
if __name__ == "__main__":
download()