Begin building out clash detection for add func

This commit is contained in:
2026-11-09 20:54:58 +11:00
parent 91ab41423d
commit dc6d7f9503
+24 -6
View File
@@ -1,3 +1,4 @@
from datetime import datetime, timedelta
import typer import typer
@@ -9,9 +10,7 @@ app = typer.Typer(help="Calendar Clash")
def setup(): def setup():
"""Begin the application by creating the events database if this is the first time running.""" """Begin the application by creating the events database if this is the first time running."""
typer.echo("Setting up the database") typer.echo("Setting up the database")
db_init() db_init()
typer.echo("Events Database successfully created") typer.echo("Events Database successfully created")
@app.command() @app.command()
@@ -20,18 +19,37 @@ def say():
@app.command() @app.command()
def add(): def add():
while True:
name = input("Event Name: ") name = input("Event Name: ")
day = input("Day of Event: ") date = input("Date of Event (DD-MM-YY): ")
time = input("Time of Event: ") time = input("Time of Event (HH:MM): ")
length = input("Length of Event: ") length = input("Length of Event: ")
description = input("Description 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(name)
print(day) print(date)
print(time) print(time)
print(length) print(length)
print(description) print(description)
if __name__ == "__main__": if __name__ == "__main__":
app() app()