Compare commits
13
Commits
17147307b7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a62da7298f | ||
|
|
d57da6c604 | ||
|
|
dc6d7f9503 | ||
|
|
91ab41423d | ||
|
|
6747254682 | ||
|
|
b292ab2de9 | ||
|
|
0fe57174f1 | ||
|
|
f6a480b1b9 | ||
|
|
db449c5b85 | ||
|
|
f23a29d494 | ||
|
|
a4f6e08ab0 | ||
|
|
412f13692a | ||
|
|
1477d9ac7f |
@@ -1,3 +1,86 @@
|
||||
# cs50-Final-Project
|
||||
|
||||
CLI calendar conflict tool
|
||||
|
||||
Code block for reverse engineering
|
||||
from datetime import datetime, timedelta
|
||||
import sqlite3
|
||||
import typer
|
||||
|
||||
@app.command()
|
||||
def add():
|
||||
while True:
|
||||
name = input("Event Name: ")
|
||||
date_input = input("Date of Event (DD-MM-YY): ")
|
||||
time = input("Time of Event (HH:MM): ")
|
||||
length_str = input("Length of Event (in minutes): ")
|
||||
description = input("Description of Event: ")
|
||||
|
||||
try:
|
||||
# Try parsing the inputs
|
||||
parsed_date = datetime.strptime(date_input, "%d-%m-%y")
|
||||
db_date = parsed_date.strftime("%Y-%m-%d")
|
||||
start_datetime = datetime.strptime(f"{db_date} {time}", "%Y-%m-%d %H:%M")
|
||||
duration = int(length_str)
|
||||
end_datetime = start_datetime + timedelta(minutes=duration)
|
||||
|
||||
# If parsing succeeds with no errors, break out of the retry loop
|
||||
break
|
||||
|
||||
except ValueError:
|
||||
# If a typing mistake happens, show red error and loop back to the start
|
||||
error_message = "Error: Invalid format. Please use DD-MM-YY for date, HH:MM for time, and a number for length. Let's try again.\n"
|
||||
typer.echo(typer.style(error_message, fg=typer.colors.RED), err=True)
|
||||
|
||||
# 2. Query existing events using the verified db_date for clash detection
|
||||
conn = sqlite3.connect("events")
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("SELECT name, time, length FROM events WHERE date = ?", (db_date,))
|
||||
existing_events = cursor.fetchall()
|
||||
|
||||
# 3. Check for clashes
|
||||
for existing_name, existing_time, existing_length in existing_events:
|
||||
ex_start = datetime.strptime(f"{db_date} {existing_time}", "%Y-%m-%d %H:%M")
|
||||
ex_end = ex_start + timedelta(minutes=int(existing_length))
|
||||
|
||||
if start_datetime < ex_end and ex_start < end_datetime:
|
||||
print(f"\n❌ Clash detected! Conflicts with existing event: '{existing_name}' ({existing_time} - {ex_end.strftime('%H:%M')})")
|
||||
conn.close()
|
||||
return # Exit the command if there's a clash
|
||||
|
||||
# 4. Save to database if no clashes
|
||||
cursor.execute(
|
||||
"INSERT INTO events (name, date, time, length, description) VALUES (?, ?, ?, ?, ?)",
|
||||
(name, db_date, time, duration, description)
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print("\n✅ Event successfully added without clashes!")
|
||||
|
||||
# 1. Open connection and use your helper to create the cursor
|
||||
conn = sqlite3.connect("events")
|
||||
cursor = create_cursor(conn) # <--- Using your helper function here!
|
||||
|
||||
# 2. Query existing events
|
||||
cursor.execute("SELECT name, time, length FROM events WHERE date = ?", (db_date,))
|
||||
existing_events = cursor.fetchall()
|
||||
|
||||
# 3. Check for clashes
|
||||
for existing in existing_events:
|
||||
# Because of your helper, you can use column names instead of numbers!
|
||||
existing_name = existing["name"]
|
||||
existing_time = existing["time"]
|
||||
existing_length = existing["length"]
|
||||
|
||||
ex_start = datetime.strptime(f"{db_date} {existing_time}", "%Y-%m-%d %H:%M")
|
||||
ex_end = ex_start + timedelta(minutes=int(existing_length))
|
||||
|
||||
if start_datetime < ex_end and ex_start < end_datetime:
|
||||
print(f"\n❌ Clash detected! Conflicts with existing event: '{existing_name}' ({existing_time} - {ex_end.strftime('%H:%M')})")
|
||||
conn.close()
|
||||
return
|
||||
|
||||
# Don't forget to close your connection when done
|
||||
conn.close()
|
||||
|
||||
+4
-1
@@ -7,10 +7,13 @@ authors = [
|
||||
{ name = "Wylie Campbell", email = "wylie@kitsch.digital" }
|
||||
]
|
||||
requires-python = ">=3.14"
|
||||
dependencies = []
|
||||
dependencies = [
|
||||
"typer[all]>=0.27.3",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
cs50-final-project = "cs50_final_project:main"
|
||||
start = "cs50_final_project.main:app"
|
||||
|
||||
[build-system]
|
||||
requires = ["uv_build>=0.12.5,<0.13.0"]
|
||||
|
||||
@@ -1,2 +1,14 @@
|
||||
|
||||
import sqlite3
|
||||
|
||||
import typer
|
||||
|
||||
from .helpers import create_db
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("Hello from cs50-final-project!")
|
||||
db = sqlite3.connect("events")
|
||||
|
||||
db.autocommit = True
|
||||
|
||||
create_db(db)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import sqlite3
|
||||
|
||||
import typer
|
||||
|
||||
from cs50_final_project.helpers import create_db
|
||||
|
||||
|
||||
def db_init() -> None:
|
||||
db = sqlite3.connect("events.db")
|
||||
|
||||
db.autocommit = True
|
||||
|
||||
create_db(db)
|
||||
@@ -1,9 +1,20 @@
|
||||
def create_db(db):
|
||||
# Create table storing calendar events
|
||||
db.execute("""
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
import sqlite3
|
||||
|
||||
|
||||
def create_cursor(conn):
|
||||
cursor = conn.cursor()
|
||||
cursor.row_factory = sqlite3.Row
|
||||
return cursor
|
||||
|
||||
def create_db(conn):
|
||||
cursor = create_cursor(conn)
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS events(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
time DATETIME NOT NULL
|
||||
length INT NOT NULL,);
|
||||
""")
|
||||
description TEXT,
|
||||
start_time DATETIME NOT NULL,
|
||||
length INT NOT NULL,
|
||||
all_day BOOL NOT NULL,
|
||||
date_created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)""");
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import sqlite3 # Make sure sqlite3 is imported
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import typer
|
||||
|
||||
from cs50_final_project.db import db_init
|
||||
from cs50_final_project.helpers import create_cursor
|
||||
|
||||
app = typer.Typer(help="Calendar Clash")
|
||||
|
||||
@app.command()
|
||||
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()
|
||||
def say():
|
||||
print("hello")
|
||||
|
||||
@app.command()
|
||||
def add():
|
||||
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)
|
||||
|
||||
conn = sqlite3.connect("events.db")
|
||||
cursor = create_cursor(conn)
|
||||
|
||||
cursor.execute("SELECT name, time, length FROM events WHERE date = ?", (iso_date,))
|
||||
existing_events = cursor.fetchall()
|
||||
|
||||
for existing_name, existing_time, existing_length in existing_events:
|
||||
ex_start = datetime.strptime(f"{iso_date} {existing_time}", "%Y-%m-%d %H:%M")
|
||||
ex_end = ex_start + timedelta(minutes=int(existing_length))
|
||||
|
||||
if start_datetime < ex_end and ex_start < end_datetime:
|
||||
print(f"\n Clash detected! Conflicts with existing event: '{existing_name}' ({existing_time} - {ex_end.strftime('%H:%M')})")
|
||||
conn.close()
|
||||
return
|
||||
|
||||
# Close connection if no clash found
|
||||
conn.close()
|
||||
|
||||
cursor.execute(
|
||||
"INSERT INTO events (name, start_time, length, description) VALUES (?, ?, ?, ?, ?)",
|
||||
(name, iso_date, time, duration, description)
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
typer.secho("\nEvent successfully added without clashes!", fg=typer.colors.GREEN)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
@@ -0,0 +1,14 @@
|
||||
Functions of the program
|
||||
|
||||
clash-add
|
||||
|
||||
1. Prompt for: name, day, time, length and optional description
|
||||
2. Check for clashes, return clashes and return apology if any found
|
||||
3. Add the user provided event data to DB
|
||||
4. Alert that the event was added with no clashes (perhaps include a visualisation of the date and time of the event and if any other event occurs soon before or after)
|
||||
|
||||
clash_view
|
||||
|
||||
1. Prompt user as to whether they either a) want to view a particular event or b) events at a particular date and or time
|
||||
2. If user wants to view a particular event request the event name, with optional granualarity for date and time (useful if events share names, such as in recurring events)
|
||||
3. if user wants to view all events on a particular date or time prompt user for relevant date/time info
|
||||
@@ -0,0 +1,99 @@
|
||||
version = 1
|
||||
revision = 3
|
||||
requires-python = ">=3.14"
|
||||
|
||||
[[package]]
|
||||
name = "annotated-doc"
|
||||
version = "0.0.5"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/5a/8e/38aa427ed5402449e226975b649c5dc73ccadfefeb95e6aecb8f8ea4b6b6/annotated_doc-0.0.5.tar.gz", hash = "sha256:c7e58ce09192557605d8bbd92836d7e1d520ac9580096042c0bfd197efacf1bb", size = 10758, upload-time = "2026-07-28T13:50:58.129Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/3e/30/e900b21425a860e195f32e37657aa1f7c7f2b1bfb26f03ca209b90933c06/annotated_doc-0.0.5-py3-none-any.whl", hash = "sha256:117bac03a25ede5df5440e855b32d556049ca169ead221505badf432fed4b101", size = 5302, upload-time = "2026-07-28T13:50:57.239Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cs50-final-project"
|
||||
version = "0.1.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "typer" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [{ name = "typer", extras = ["all"], specifier = ">=0.27.3" }]
|
||||
|
||||
[[package]]
|
||||
name = "markdown-it-py"
|
||||
version = "4.2.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "mdurl" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/06/ff/7841249c247aa650a76b9ee4bbaeae59370dc8bfd2f6c01f3630c35eb134/markdown_it_py-4.2.0.tar.gz", hash = "sha256:04a21681d6fbb623de53f6f364d352309d4094dd4194040a10fd51833e418d49", size = 82454, upload-time = "2026-05-07T12:08:28.36Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/81/4da04ced5a082363ecfa159c010d200ecbd959ae410c10c0264a38cac0f5/markdown_it_py-4.2.0-py3-none-any.whl", hash = "sha256:9f7ebbcd14fe59494226453aed97c1070d83f8d24b6fc3a3bcf9a38092641c4a", size = 91687, upload-time = "2026-05-07T12:08:27.182Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mdurl"
|
||||
version = "0.1.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729, upload-time = "2022-08-14T12:40:10.846Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979, upload-time = "2022-08-14T12:40:09.779Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pygments"
|
||||
version = "2.21.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rich"
|
||||
version = "15.0.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "markdown-it-py" },
|
||||
{ name = "pygments" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c0/8f/0722ca900cc807c13a6a0c696dacf35430f72e0ec571c4275d2371fca3e9/rich-15.0.0.tar.gz", hash = "sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36", size = 230680, upload-time = "2026-04-12T08:24:00.75Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/82/3b/64d4899d73f91ba49a8c18a8ff3f0ea8f1c1d75481760df8c68ef5235bf5/rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb", size = 310654, upload-time = "2026-04-12T08:24:02.83Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shellingham"
|
||||
version = "1.5.4"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/58/15/8b3609fd3830ef7b27b655beb4b4e9c62313a4e8da8c676e142cc210d58e/shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de", size = 10310, upload-time = "2023-10-24T04:13:40.426Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755, upload-time = "2023-10-24T04:13:38.866Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typer"
|
||||
version = "0.27.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "annotated-doc" },
|
||||
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||
{ name = "rich" },
|
||||
{ name = "shellingham" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/03/51/d33db42cc72ffd8c30777547b42d01f0cbf9d95a770457698d0174b3ed71/typer-0.27.3.tar.gz", hash = "sha256:d0396f770a560ab1b0a8504e13b5f254b728cedb05c61cf0359e944e50ce8901", size = 205303, upload-time = "2026-10-06T17:24:16.61Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/07/ea/2e31b67051e91a133189e9c000c222502ddc6969856416de0d095de4c0b0/typer-0.27.3-py3-none-any.whl", hash = "sha256:e50022f28b82a86313e54501317a1db64bf8f8d036ff8cfe5ca7e47675454aff", size = 123312, upload-time = "2026-10-06T17:24:15.054Z" },
|
||||
]
|
||||
Reference in New Issue
Block a user