diff --git a/application/database.py b/application/database.py index 73a3d6d..18a8d53 100644 --- a/application/database.py +++ b/application/database.py @@ -3,6 +3,7 @@ import requests # from datetime import datetime import time import random +import copy class TodoDatabase: def __init__(self, filename="data.json"): @@ -15,9 +16,11 @@ class TodoDatabase: pass def save_todo(self, date, todo, save=True): + if "recurring" not in self.database: + self.database["recurring"] = [] if date not in self.database: # if not len(self.database[date]) > 0: - self.database[date] = [] + self.database[date] = copy.deepcopy(self.database["recurring"]) if todo.recurring: self.database["recurring"].append(todo.model_dump()) self.database[date].append(todo.model_dump()) diff --git a/application/main.py b/application/main.py index e411b11..1bb4691 100644 --- a/application/main.py +++ b/application/main.py @@ -18,7 +18,7 @@ app = FastAPI() auth = VerifyToken() data = TodoDatabase() printer = ThermalPrinter(data) -printer.print_default() #temp debug +# printer.print_default() #temp debug @@ -40,13 +40,14 @@ class TodoDate(BaseModel): class PrintAction(BaseModel): date: str = datetime.today().strftime('%Y-%m-%d') action: str #Options: - # default (pulls current todos from date, needs date) + # all (pulls current todos from date, needs date) # sudoku (prints a random sudoku) # todos (prints only dates todos) # wordsearch (prints a random wordsearch) # quote (prints a random quote) # greeting (prints a greeting) - # + # sentence (prints a custom message) + sentence: str = "" # @app.get("/api/public") # def public(): @@ -118,7 +119,7 @@ def write_todos(todos: TodoList, auth_result: str = Security(auth.verify)): @app.get("/api/todos/print") -def print_todos(date: PrintAction, auth_result: str = Security(auth.verify)): +def print_todos(action: PrintAction, auth_result: str = Security(auth.verify)): """A valid access token is required to access this route""" # result = { @@ -127,9 +128,42 @@ def print_todos(date: PrintAction, auth_result: str = Security(auth.verify)): # {"time": "2:00pm to 3:00pm", "text": "Go for a walk"} # ] # } #TODO: replace with access to database if no todos provided from request, otherwise print request data + + #Options: + # all (pulls current todos from date, needs date) + # sudoku (prints a random sudoku) + # todos (prints only dates todos) + # wordsearch (prints a random wordsearch) + # quote (prints a random quote) + # greeting (prints a greeting) + # sentence (prints a custom message) + if action.action == "all": + printer.print_default() - todos = data.get_todos(date) - printer.print_todos() + if action.action == "sudoku": + printer.print_sudoku() + + if action.action == "todos": + printer.print_todos() + + if action.action == "wordsearch": + printer.print_wordsearch() + + if action.action == "quote": + printer.print_random_quote() + + if action.action == "greeting": + printer.print_greeting() + + if action.action == "sentence": + printer.print_custom(action.sentence) + + + printer.finished_printing() + + + # todos = data.get_todos(action.date) + # printer.print_todos() return {"result": "success"} diff --git a/application/static/index.html b/application/static/index.html index afb80bf..74e8c5b 100644 --- a/application/static/index.html +++ b/application/static/index.html @@ -21,6 +21,102 @@ + + + +
+ + +
+