Add todo file parsing

This commit is contained in:
2025-11-25 22:21:32 -05:00
parent 3336973940
commit 752433ee8e
3 changed files with 35 additions and 1 deletions

13
codupoc/slimdownparser.py Normal file
View File

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

11
codupoc/todo.py Normal file
View File

@@ -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}"

View File

@@ -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.
def read_todos(self) -> list[Todo]:
todos = []
f = self.open_todo_file()
for line in f:
todos.append(parse_todo(line))
return todos