File size: 676 Bytes
846683d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from pathlib import Path
from typing import Any


def _tasks_dir() -> Path:
    return Path(__file__).resolve().parent.parent / "tasks"


def load_tasks(difficulty: str = "easy") -> list[dict[str, Any]]:
    file_path = _tasks_dir() / f"{difficulty}.json"
    if not file_path.exists():
        raise FileNotFoundError(f"Task file not found: {file_path}")

    with file_path.open("r", encoding="utf-8") as handle:
        payload = json.load(handle)

    if isinstance(payload, dict) and "tasks" in payload:
        return payload["tasks"]

    if isinstance(payload, list):
        return payload

    raise ValueError(f"Unsupported task format in {file_path}")