| 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 | |