File size: 1,060 Bytes
1b8aef5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import importlib.resources
import json
from pathlib import Path


__questions_path = (
        Path(str(importlib.resources.files("data"))) / "questions.jsonl"
)


def get_question(task_id: str) -> str | None:
    """
    Given the ID of one of the available questions, reads it from
    the JSONL file where questions have been previously downloaded.

    Args:
        task_id: The hash code of the question.

    Returns:
        The JSONL string with the required question.
    """
    with open(__questions_path, 'r', encoding='utf-8') as file:
        for line in file:
            data = json.loads(line)
            if data["task_id"] == task_id:
                return line

    return None


def get_all_questions() -> list[str]:
    """
    Retrieves the list of all questions previously downloaded.

    Returns:
        The list of questions previously downloaded.
    """
    questions = []
    with open(__questions_path, 'r', encoding='utf-8') as file:
        for line in file:
            questions += [json.loads(line)]
    return questions