def addTask(taskModels): os.system("clear") printColor(text="Set description of task: ", color=Color.BLUE) description = descriptionValidation() printColor(text="Set start day of task: ", color=Color.BLUE) dateStart = dateStartValidation() printColor(text="Task is important?: ", color=Color.BLUE) important = importantValidation() printColor(text="Task is all day?: ", color=Color.BLUE) allDay = allDayValidation() newTask = TaskModel(description=description, startDate=dateStart) newTask.setImportant(important) newTask.setAllDay(allDay) if allDay == False: printColor(text="Set start day of task: ", color=Color.BLUE) endDate = endDateValidation() newTask.addEndDate(endDate) taskModels.append(newTask)
def inputYN(communicate): while True: printColor(text=communicate, color=Color.RED) decision = input("decision (y/n): ").lower() if decision == "y" or decision == "n": break return decision
def endDateValidation(): while True: endDate = input("End day (dd-mm-yyyy): ") if re.search(dateRegex, endDate): break else: os.system("clear") printColor(text="Date pattern: dd-mm-yyyy", color=Color.RED) printColor(text="End day (dd-mm-yyyy): ", color=Color.BLUE) return endDate
def dateStartValidation(): while True: dateStart = input("Start day (dd-mm-yyyy): ") if re.search(dateRegex, dateStart): break else: os.system("clear") printColor(text="Date pattern: dd-mm-yyyy", color=Color.RED) printColor(text="Start day (dd-mm-yyyy): ", color=Color.BLUE) return dateStart
def descriptionValidation(): while True: description = input("description (text): ") if 0 < len(description) < 40: break else: os.system("clear") printColor(text="Description have to from 1 to 40 letters!", color=Color.RED) printColor(text="Set description of task: ", color=Color.BLUE) return description
def inputNumberMinMax(communicate, min, max): while True: number = input(communicate) if number.lower() == "exit": break number = int(number) if number.isdigit() else max + 1 if number < max and number >= min: break else: printColor(text="Invalid input!", color=Color.RED) return number
def allDayValidation(): while True: allDay = input("all day (y/n): ") if allDay == "y" or allDay == "n": allDay = True if allDay == "y" else False break else: os.system("clear") printColor(text="Invalid command set y or n", color=Color.RED) printColor(text="Task is all day?: ", color=Color.BLUE) return allDay
def importantValidation(): while True: important = input("important (y/n): ") if important == "y" or important == "n": important = True if important == "y" else False break else: os.system("clear") printColor(text="Invalid command set y or n", color=Color.RED) printColor(text="Task is important?: ", color=Color.BLUE) return important
def removeTask(taskModels): showTasks(taskModels) printColor("") idTaskToRemove = inputNumberMinMax( communicate="select task id to remove or exit to back: ", min=0, max=len(taskModels)) if idTaskToRemove == "exit": return decision = inputYN( communicate=f"Are you sure to delete {idTaskToRemove} task?") if decision == "y": del taskModels[idTaskToRemove]
def showCurrentTask(taskModels): date = datetime.now() currentTask = list(filter(lambda x: x.StartDate > date, taskModels)) currentTask = sorted(currentTask, key=lambda x: x.StartDate) color = Color.CYAN printColor(f"next task: ", color=Color.RED) printColor(f"day: {currentTask[0].StartDate}", color=color) printColor(f"descritprion: {currentTask[0].Description}", color=color) printColor(f"important: {currentTask[0].Important}", color=color)
def showMenu(): printColor(text="..............", color=Color.RED) printColor(text=".....MENU.....", color=Color.RED) printColor(text="Exit: exit", color=Color.GREEN) printColor(text="Add task: add", color=Color.GREEN) printColor(text="Show tasks: show", color=Color.GREEN) printColor(text="Remove task: remove", color=Color.GREEN) printColor(text="Save tasks: save", color=Color.GREEN) printColor(text="Load tasks: load", color=Color.GREEN) printColor(text="..............", color=Color.RED) printColor("")
def showTasks(taskModels): os.system("clear") numberAsterix = 75 printColor(text="." * numberAsterix, color=Color.RED) text = "lp| " text += "Description" + " " * 9 + " | " text += "Date " + " " * 10 + "|" text += f" important |" text += f" allDay |" text += f" EndDate |" printColor(text=text) printColor(text="." * numberAsterix, color=Color.BLUE) lengthTask = len(taskModels) for index, task in enumerate(taskModels): task_description_line = [] if len(task.Description) > 20: task_description_line.append(task.Description[0:20]) task_description_line.append(task.Description[20:]) else: task_description_line.append(task.Description) if len(task_description_line) > 1: space = len(task_description_line[0]) - len( task_description_line[1]) line = f"{index} |" line += f" {task_description_line[0]} |" line += f" {task.StartDate}" + " " * 5 + "|" line += " " * 3 + f"{task.Important}" + " " * 3 + "|" line += " " * 2 + f"{task.AllDay}" + " " * 2 + "|" line += " " * 3 + f"{task.EndDate}" + " " * 2 + "|" printColor(line) line = f" | {task_description_line[1]}" line += " " * space + " | " line += " " * 15 + "|" line += " " * 11 + "|" line += " " * 9 + "|" line += " " * 9 + "|" printColor(line) if lengthTask != index + 1: printColor(text="." * numberAsterix, color=Color.BLUE) else: space = 20 - len(task_description_line[0]) line = f"{index} |" line += f" {task_description_line[0]}" line += " " * space line += f" | {task.StartDate}" line += " " * 5 + "|" line += " " * 3 + f"{task.Important}" + " " * 3 + "|" line += " " * 2 + f"{task.AllDay}" + " " * 2 + "|" line += " " * 3 + f"{task.EndDate}" + " " * 2 + "|" printColor(line) if lengthTask != index + 1: printColor(text="." * numberAsterix, color=Color.BLUE) printColor(text="." * numberAsterix, color=Color.RED)