fix(Packagers): changed to first time run

This commit is contained in:
darkicewolf50 2024-12-07 20:07:57 -07:00
parent a9460dc692
commit 49313e8450
10 changed files with 171 additions and 115 deletions

Binary file not shown.

View File

@ -5,12 +5,10 @@ import time
from NoSheet import NoSheet from NoSheet import NoSheet
import datetime import datetime
import os
""" """
TODO update to possibly not use pandas and update to use the new template TODO change to use new tempate
TODO update name of function to be more clear TODO change names to be more clear
""" """
def ReadDatabase(): def ReadDatabase():
@ -33,9 +31,6 @@ def ReadDatabase():
excel_file_path = f"OR{year_donation}-L-Interview Data.xlsx" excel_file_path = f"OR{year_donation}-L-Interview Data.xlsx"
lock_file_path = f"OR{year_donation}-L-Interview Data.xlsx.lock" lock_file_path = f"OR{year_donation}-L-Interview Data.xlsx.lock"
if not (os.path.isfile(excel_file_path) or os.path.isfile(lock_file_path)):
NoSheet()
else:
# Retry parameters # Retry parameters
max_retries = 60 # Maximum number of retries if the file is locked max_retries = 60 # Maximum number of retries if the file is locked
retry_interval = 0.5 # Wait time (in seconds) between retries retry_interval = 0.5 # Wait time (in seconds) between retries

View File

@ -4,15 +4,13 @@ from openpyxl import load_workbook
from send_email import send_email from send_email import send_email
from filelock import FileLock from filelock import FileLock
from NoSheet import NoSheet
import datetime import datetime
import os
""" """
TODO update to possibly not use pandas and update to use the new template TODO make it work with the new template
TODO update name of functions to be more clear TODO update names to be more clear
TODO try to remove pandas
""" """
def ReadDatabase(): def ReadDatabase():
""" """
Reads the Database to retrieve available interview slots Reads the Database to retrieve available interview slots
@ -31,10 +29,6 @@ def ReadDatabase():
file_path = f"OR{year_donation}-L-Interview Data.xlsx" file_path = f"OR{year_donation}-L-Interview Data.xlsx"
lock_path = f"OR{year_donation}-L-Interview Data.xlsx.lock" lock_path = f"OR{year_donation}-L-Interview Data.xlsx.lock"
# checks for if the file exisits for the year otherwise it will create one
if not (os.path.isfile(file_path) or os.path.isfile(lock_path)):
NoSheet()
else:
# Use a file-based lock for thread-safe and process-safe access # Use a file-based lock for thread-safe and process-safe access
with FileLock(lock_path): with FileLock(lock_path):
# Load the Excel file into a pandas DataFrame with specific columns # Load the Excel file into a pandas DataFrame with specific columns
@ -84,11 +78,6 @@ def AppendAppointment(date, start_time, interviewee_name, interviewee_email):
file_path = f"OR{year_donation}-L-Interview Data.xlsx" file_path = f"OR{year_donation}-L-Interview Data.xlsx"
lock_path = f"OR{year_donation}-L-Interview Data.xlsx.lock" lock_path = f"OR{year_donation}-L-Interview Data.xlsx.lock"
# checks for if the file exisits for the year otherwise it will create one
if not (os.path.isfile(file_path) or os.path.isfile(lock_path)):
NoSheet()
else:
available_slots = ReadDatabase() available_slots = ReadDatabase()
# Check if the requested slot is available in the `available_slots` structure # Check if the requested slot is available in the `available_slots` structure

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,62 @@
from ReadDB import ReadDatabase
def getSchedulePackager():
"""
Packages up the response for a http response
``REQUIRES``: None
``PROMISES``: ``JSON`` http response ready
``Develop in part by``: Brock T
``Contact``: darkicewolf50@gmail.ocm
"""
return {
"interviewDates": ReadDatabase()
}
from WriteDB import AppendAppointment
from email_validator import validate_email, EmailNotValidError
def SelectAppointment (appointmentJson):
"""
Packages up a response for a http request
``REQUIRES``: ``JSON`` with the data of interviewee name, date, starttime and interviewee email
``PROMISES``: ``JSON`` Returns if the booking was a success
``Developed in part by``: Brock
``Contact``: darkicewolf50@gmail.com
"""
"""
Example of an incoming http post body
{
"intervieweeName": "Brock",
"date": "2024-09-16",
"startTime": "10:30:00",
"intervieweeEmail": "darkicewolf50@gmail.com"
}
"""
try:
validEmail = validate_email(appointmentJson["intervieweeEmail"], check_deliverability=True)
if validEmail:
status = AppendAppointment(date=appointmentJson["date"], start_time=appointmentJson["startTime"], interviewee_name=appointmentJson["intervieweeName"], interviewee_email=appointmentJson["intervieweeEmail"])
if status:
resBody = {"Success": True, "validEmail": "true"}
else:
resBody = {"Success": False, "validEmail": "true"}
# resBody["message"] = appointmentJson for testing
return resBody
except EmailNotValidError as e:
return {"Success": False, "validEmail": "false"}

12
main.py
View File

@ -1,8 +1,18 @@
import json
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from pydantic import BaseModel from pydantic import BaseModel
from NoSheet import NoSheet
import datetime
import os
year_donation = int(str(datetime.datetime.now().year)[2:]) + 1 # gets the last two digits of the current year then adds 1 for the current season
# name based off the 2025 naming system
# Define the path to the Excel file and the lock file
file_name = f"OR{year_donation}-L-Interview Data.xlsx"
if not os.path.isfile(file_name):
NoSheet()
app = FastAPI() app = FastAPI()
@app.get("/") @app.get("/")