Begin building out clash detection for add func
This commit is contained in:
@@ -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():
|
||||
while True:
|
||||
name = input("Event Name: ")
|
||||
day = input("Day of Event: ")
|
||||
time = input("Time of Event: ")
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user