diff --git a/codupoc/slimdownparser.py b/codupoc/slimdownparser.py new file mode 100644 index 0000000..fab829a --- /dev/null +++ b/codupoc/slimdownparser.py @@ -0,0 +1,13 @@ +import re + +from todo import Todo + +TODO_PATTERN = r"^-\[( |X)\] (.+)$" + +def parse_todo(line: str) -> Todo: + pattern = re.compile(TODO_PATTERN) + match = pattern.match(line) + (x, item) = match.group(1, 2) + is_checked = x == "X" + + return Todo(item, is_checked) \ No newline at end of file diff --git a/codupoc/todo.py b/codupoc/todo.py new file mode 100644 index 0000000..fb2d00e --- /dev/null +++ b/codupoc/todo.py @@ -0,0 +1,11 @@ +from base64_random import gen_random_base64 + + +class Todo: + def __init__(self, item: str, checked: bool): + self.item = item + self.checked = checked + self.lid = gen_random_base64(10) + + def __str__(self): + return f"- [{self.checked}] {self.item}" \ No newline at end of file diff --git a/codupoc/todomanager.py b/codupoc/todomanager.py index b61e7c2..051277b 100644 --- a/codupoc/todomanager.py +++ b/codupoc/todomanager.py @@ -1,6 +1,9 @@ import sys from os import path +from todo import Todo +from slimdownparser import parse_todo + class TodoManager: filename = "todo.md" @@ -14,4 +17,11 @@ class TodoManager: self.file = open(self.filename, "a") return self.file - # Parse and save file as needed. \ No newline at end of file + def read_todos(self) -> list[Todo]: + todos = [] + f = self.open_todo_file() + + for line in f: + todos.append(parse_todo(line)) + + return todos \ No newline at end of file