# Importuje to co pochodzi z systemu import asyncio import json from pathlib import Path # Importuje to co doinstalowałem import aiofiles # Importuje moje własne pliki TASKS_FILE = Path("tasks.json") async def load_tasks(): if not TASKS_FILE.exists(): return [] async with aiofiles.open(TASKS_FILE, "r", encoding="utf8") as file: content = await file.read() return json.loads(content) if content else [] async def save_tasks(tasks): async with aiofiles.open(TASKS_FILE, "w", encoding="utf8") as file: await file.write(json.dumps(tasks, indent=1)) async def add_task(description): tasks = await load_tasks() tasks.append({"description": description, "done": False}) await save_tasks(tasks) async def list_tasks(): tasks = await load_tasks() return tasks async def complete_tasks(index): tasks = await load_tasks() if 0 <= index <= len(tasks): tasks[index]["done"] = True await save_tasks(tasks) return True return False