feat(putTogether): read db also combined

This commit is contained in:
darkicewolf50 2024-11-30 15:35:56 -07:00
parent 838e53905a
commit 76632341e5
12 changed files with 37 additions and 23 deletions

View File

@ -1,6 +1,8 @@
import yaml import yaml
import json import json
from ReadDB import ReadDatabase
with open("./MockDB/schedule.yaml", "r") as scheduleyml: with open("./MockDB/schedule.yaml", "r") as scheduleyml:
ymlschedule = yaml.safe_load(scheduleyml) ymlschedule = yaml.safe_load(scheduleyml)
@ -17,8 +19,7 @@ def getSchedulePackager():
``Contact``: darkicewolf50@gmail.ocm ``Contact``: darkicewolf50@gmail.ocm
""" """
return { return {
"interviewDates": json.dumps(ymlschedule) "interviewDates": ReadDatabase()
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -29,8 +29,8 @@ def get_root():
from GetSchedulePackager import getSchedulePackager from GetSchedulePackager import getSchedulePackager
@app.get("/getSchedule") @app.get("/getAppointments")
async def getSchedule(): async def getAppointments():
res = getSchedulePackager() res = getSchedulePackager()

View File

@ -1,4 +1,5 @@
from WriteDB import AppendAppointment from WriteDB import AppendAppointment
from email_validator import validate_email, EmailNotValidError
def SelectAppointment (appointmentJson): def SelectAppointment (appointmentJson):
@ -15,17 +16,29 @@ def SelectAppointment (appointmentJson):
``Contact``: darkicewolf50@gmail.com ``Contact``: darkicewolf50@gmail.com
""" """
"""
{
"intervieweeName": "Alice Johnson",
"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"}
status = AppendAppointment(date=appointmentJson["date"], start_time=appointmentJson["startTime"], interviewee_name=appointmentJson["intervieweeName"], interviewee_email=appointmentJson["intervieweeEmail"]) # resBody["message"] = appointmentJson for testing
return resBody
if status: except EmailNotValidError as e:
resBody = {"Success": True} return {"Success": False, "validEmail": "false"}
else:
resBody = {"Success": False}
# resBody["message"] = appointmentJson for testing
return resBody
if __name__ == "__main__": if __name__ == "__main__":
print(SelectAppointment("10:00 AM")) print(SelectAppointment("10:00 AM"))

View File

@ -78,7 +78,7 @@ def send_email(interviewee_email="darkicewolf50@gmail.com", interviewee_name="br
server.login(gmail_user, gmail_apppassword) server.login(gmail_user, gmail_apppassword)
server.sendmail(gmail_user, [interviewee_email, static_email], msg.as_string()) server.sendmail(gmail_user, [interviewee_email, static_email], msg.as_string())
server.quit() server.quit()
print(f"Email sent successfully to {interviewee_email} and {static_email}.") # print(f"Email sent successfully to {interviewee_email} and {static_email}.")
except Exception as e: except Exception as e:
print(f"Failed to send email: {e}") print(f"Failed to send email: {e}")

View File

@ -8,18 +8,18 @@ def BenchMarkServer():
#print(json.dumps(res, indent=1)) #print(json.dumps(res, indent=1))
def BenchMarkDjango(): def BenchMarkDjango():
rawRes = requests.get("http://localhost:8000/getSchedule") rawRes = requests.get("http://127.0.0.1:8000/getAppointments")
res = json.loads(rawRes.text) res = json.loads(rawRes.text)
# print(json.dumps(res, indent=1)) #print(json.dumps(res, indent=1))
if __name__ == "__main__": if __name__ == "__main__":
test = 0 test = 1
if test: if test:
djangoTime = timeit.timeit(stmt=BenchMarkDjango, number=10) djangoTime = timeit.timeit(stmt=BenchMarkDjango, number=1000)
pythonTime = timeit.timeit(stmt=BenchMarkServer, number=10) # pythonTime = timeit.timeit(stmt=BenchMarkServer, number=10)
print(f"FastAPI: {djangoTime}\nPython: {pythonTime}") print(f"FastAPI: {djangoTime}\nPython: ")
reqbody = { reqbody = {
"body": {"message": "hello"} "body": {"message": "hello"}
} }
rawRes = requests.post("http://localhost:8000/SelectInterview", reqbody) # rawRes = requests.post("http://localhost:8000/SelectInterview", reqbody)