From 7225ee331a82cf1f8d8afab8923c4f35a792e5b8 Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 10 Jun 2024 19:57:37 +0800 Subject: refactor: improve bots/todo-* (#41) --- bots/todo-py/tools.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'bots/todo-py') diff --git a/bots/todo-py/tools.py b/bots/todo-py/tools.py index 29e13ea..a531b51 100644 --- a/bots/todo-py/tools.py +++ b/bots/todo-py/tools.py @@ -32,7 +32,8 @@ def del_todo(id: int): with open(todos_file, "r") as f: data = json.load(f) except (FileNotFoundError, JSONDecodeError): - _die("Empty todo list") + print("Empty todo list") + return data = [item for item in data if item["id"] != id] with open(todos_file, "w") as f: json.dump(data, f) @@ -46,7 +47,7 @@ def list_todos(): with open(todos_file, "r") as f: print(f.read()) except FileNotFoundError: - _die("Empty todo list") + print("[]") def clear_todos(): @@ -59,7 +60,3 @@ def _get_todos_file() -> str: if not os.path.exists(cache_dir): os.makedirs(cache_dir, exist_ok=True) return os.path.join(cache_dir, "todos.json") - -def _die(msg: str): - print(msg, file=sys.stderr) - exit(1) \ No newline at end of file -- cgit v1.2.3