diff options
author | HampusM <hampus@hampusmat.com> | 2025-01-17 20:17:15 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-01-17 20:17:15 +0100 |
commit | 16a2713edd8c34b37a91f61e5a65442d91cc6fe8 (patch) | |
tree | 38fa61a0531b9173b16736cfaa611a1bafe1f21f | |
parent | e69f05739e56d62361e5bb0dcc4db17289b0c2df (diff) |
chore: add script to organize todo list
-rw-r--r-- | organize_todo.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/organize_todo.py b/organize_todo.py new file mode 100644 index 0000000..95460ea --- /dev/null +++ b/organize_todo.py @@ -0,0 +1,57 @@ +from enum import Enum +from typing import List + + +TODO_FILE_NAME = "TODO.md" + +TODO_LINE_START_COMPLETED = "- [x] " +TODO_LINE_START_UNCOMPLETED = "- [ ] " + + +class PrevItemState(Enum): + COMPLETED = 0 + UNCOMPLETED = 1 + UNDETERMINED = 2 + + +def main(): + with open(TODO_FILE_NAME) as todo_file: + todo_lines = todo_file.readlines() + + completed: List[str] = [] + uncompleted: List[str] = [] + + prev_item_state = PrevItemState.UNDETERMINED + + for [index, line] in enumerate(todo_lines): + if len(line) == 0: + continue + + if line.startswith(TODO_LINE_START_COMPLETED): + completed.append(line) + prev_item_state = PrevItemState.COMPLETED + elif line.startswith(TODO_LINE_START_UNCOMPLETED): + uncompleted.append(line) + prev_item_state = PrevItemState.UNCOMPLETED + elif line[0].isspace(): + if prev_item_state == PrevItemState.COMPLETED: + completed.append(line) + elif prev_item_state == PrevItemState.UNCOMPLETED: + uncompleted.append(line) + elif prev_item_state == PrevItemState.UNDETERMINED: + print( + f"Error: todo line {index + 1} starts with whitespace but there is " + "no previous item" + ) + exit(1) + else: + print(f"Error: todo line {index + 1} does not have correct syntax") + exit(1) + + with open(TODO_FILE_NAME, "w") as todo_file: + todo_file.writelines(uncompleted) + todo_file.writelines(completed) + + +if __name__ == "__main__": + main() |