From dc6d7f9503ce5d2f50103c4b3ec571037771e5e3 Mon Sep 17 00:00:00 2001 From: Wylie Campbell Date: Mon, 9 Nov 2026 20:54:58 +1100 Subject: [PATCH] Begin building out clash detection for add func --- src/cs50_final_project/main.py | 36 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/cs50_final_project/main.py b/src/cs50_final_project/main.py index 17b5bf0..28a9c71 100644 --- a/src/cs50_final_project/main.py +++ b/src/cs50_final_project/main.py @@ -1,3 +1,4 @@ +from datetime import datetime, timedelta import typer @@ -9,9 +10,7 @@ app = typer.Typer(help="Calendar Clash") def setup(): """Begin the application by creating the events database if this is the first time running.""" typer.echo("Setting up the database") - db_init() - typer.echo("Events Database successfully created") @app.command() @@ -20,18 +19,37 @@ def say(): @app.command() def add(): - name = input("Event Name: ") - day = input("Day of Event: ") - time = input("Time of Event: ") - length = input("Length of Event: ") - description = input("Description of Event: ") + while True: + name = input("Event Name: ") + date = input("Date of Event (DD-MM-YY): ") + time = input("Time of Event (HH:MM): ") + length = input("Length of Event: ") + description = input("Description of Event: ") + + try: + # Check for clashes of day/time + raw_date = datetime.strptime(date, "%d-%m-%y") + iso_date = raw_date.strftime("%Y-%m-%d") + + # Add time for full iso datetime + start_datetime = datetime.strptime(f"{iso_date} {time}", "%Y-%m-%d %H:%M") + duration = int(length) + end_datetime = start_datetime + timedelta(minutes=duration) + + break + + except ValueError: + error_datetime = "Incompatible Syntax. Please use DD-MM-YY and HH:MM for date and time, respectively, as well as a whole number (in minutes) for length." + typer.echo(typer.style(error_datetime, fg=typer.colors.RED), err=True) + raise typer.Exit(code=1) +#Query events.db for existing events matching iso_date +conn = sqlite3. print(name) - print(day) + print(date) print(time) print(length) print(description) - if __name__ == "__main__": app()