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
+27 -9
View File
@@ -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()