Fix startup bug and prefix bug
This commit is contained in:
@@ -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 " "
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user