Fixed the code for date which caused issues, create a new file to ensure WriteDB and SendEmail work from any script

This commit is contained in:
HamodiGit 2024-11-30 13:37:30 -07:00
parent bcdaa37d97
commit 6ff802f604
6 changed files with 19 additions and 6 deletions

11
TestBookAppointment.py Normal file
View File

@ -0,0 +1,11 @@
from WriteDB import AppendAppointment
def TestBookAppointment():
date_1 = "2024-09-16"
start_time_1 = "10:30:00"
interviewee_name_1 = "Alice Johnson"
interviewee_email_1 = "ahmadmuhammadofficial@gmail.com"
print(f"\nTest Case 1: Trying to book {date_1} at {start_time_1} for {interviewee_name_1} ({interviewee_email_1})")
AppendAppointment(date_1, start_time_1, interviewee_name_1, interviewee_email_1)
TestBookAppointment()

View File

@ -1,7 +1,7 @@
import pandas as pd import pandas as pd
import json import json
from openpyxl import load_workbook 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
# Define the path to the Excel file and the lock file # Define the path to the Excel file and the lock file
@ -93,7 +93,7 @@ def AppendAppointment(date, start_time, interviewee_name, interviewee_email):
email_cell.value = updated_emails email_cell.value = updated_emails
workbook.save(file_path) workbook.save(file_path)
#send_email(interviewee_email, interviewee_name, date, start_time) send_email(interviewee_email, interviewee_name, date, start_time)
return True return True
# If no slots available, return that the slot is unavailable # If no slots available, return that the slot is unavailable
@ -116,7 +116,7 @@ def run_tests():
date_1 = "2024-09-16" date_1 = "2024-09-16"
start_time_1 = "10:30:00" start_time_1 = "10:30:00"
interviewee_name_1 = "Alice Johnson" interviewee_name_1 = "Alice Johnson"
interviewee_email_1 = "alice.johnson@example.com" interviewee_email_1 = "ahmadmuhammadofficial@gmail.com"
print(f"\nTest Case 1: Trying to book {date_1} at {start_time_1} for {interviewee_name_1} ({interviewee_email_1})") print(f"\nTest Case 1: Trying to book {date_1} at {start_time_1} for {interviewee_name_1} ({interviewee_email_1})")
AppendAppointment(date_1, start_time_1, interviewee_name_1, interviewee_email_1) AppendAppointment(date_1, start_time_1, interviewee_name_1, interviewee_email_1)
@ -137,4 +137,5 @@ def run_tests():
AppendAppointment(date_3, start_time_3, interviewee_name_3, interviewee_email_3) AppendAppointment(date_3, start_time_3, interviewee_name_3, interviewee_email_3)
# Run tests # Run tests
run_tests() if __name__ == "__main__":
run_tests()

Binary file not shown.

Binary file not shown.

View File

@ -20,7 +20,7 @@ def send_email(interviewee_email="darkicewolf50@gmail.com", interviewee_name="br
mst = pytz.timezone("America/Edmonton") # MST with Daylight Savings considered mst = pytz.timezone("America/Edmonton") # MST with Daylight Savings considered
# Parse the input date and time, localize to MST # Parse the input date and time, localize to MST
start_datetime = mst.localize(datetime.strptime(f"{date} {start_time}", "%d-%m-%Y %I:%M %p")) start_datetime = mst.localize(datetime.strptime(f"{date} {start_time}", "%Y-%m-%d %H:%M:%S"))
end_datetime = start_datetime + timedelta(minutes=30) end_datetime = start_datetime + timedelta(minutes=30)
# Format date and time for the calendar URLs # Format date and time for the calendar URLs
@ -78,4 +78,5 @@ def send_email(interviewee_email="darkicewolf50@gmail.com", interviewee_name="br
except Exception as e: except Exception as e:
print(f"Failed to send email: {e}") print(f"Failed to send email: {e}")
send_email() if __name__ == "__main__":
send_email()