Fix startup bug and prefix bug

This commit is contained in:
2025-12-04 18:09:32 -05:00
parent c4120ae5d1
commit 13f95a6a72
2 changed files with 13 additions and 4 deletions

View File

@@ -1,11 +1,20 @@
import random
from base64_random import gen_random_base64 from base64_random import gen_random_base64
ALPH = 'abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY'
def gen_safe_lid() -> str:
main_part = gen_random_base64(10)
prefix = random.choice(ALPH)
return prefix + main_part
class Todo: class Todo:
def __init__(self, item: str, checked: bool): def __init__(self, item: str, checked: bool):
self.item = item self.item = item
self.checked = checked self.checked = checked
self.lid = gen_random_base64(10) self.lid = gen_safe_lid()
def __str__(self): def __str__(self):
checkmark = "X" if self.checked else " " checkmark = "X" if self.checked else " "

View File

@@ -13,8 +13,8 @@ class TodoManager:
def does_todo_file_exist(self): def does_todo_file_exist(self):
return path.exists(self.filename) return path.exists(self.filename)
def open_todo_file(self): def open_todo_file(self, filemode="r+"):
self.file = open(self.filename, "r+") self.file = open(self.filename, filemode)
return self.file return self.file
def read_todos(self) -> list[Todo]: def read_todos(self) -> list[Todo]:
@@ -33,7 +33,7 @@ class TodoManager:
def get_todos(self) -> dict[str, Todo]: def get_todos(self) -> dict[str, Todo]:
if not self.does_todo_file_exist(): if not self.does_todo_file_exist():
self.open_todo_file() self.open_todo_file(filemode="w")
return {} return {}
todos = self.read_todos() todos = self.read_todos()