import datetime import smtplib from email.mime.text import MIMEText # Dictionary of patients and their appointment dates/times patients = { 'John Smith': '2022-05-01 10:00:00', 'Jane Doe': '2022-05-03 14:30:00', 'Bob Johnson': '2022-05-05 09:15:00' } # Email address and password to send reminders from from_email = '[email protected]' from_password = 'your_password' # Function to send an email reminder to a patient def send_reminder(to_email, date_time): date_time_str = date_time.strftime('%Y-%m-%d %H:%M:%S') message = 'This is a reminder that you have an appointment on ' + date_time_str msg = MIMEText(message) msg['Subject'] = 'Appointment Reminder' msg['From'] = from_email msg['To'] = to_email s = smtplib.SMTP('smtp.gmail.com', 587) s.starttls() s.login(from_email, from_password) s.send_message(msg) s.quit() # Function to check for upcoming appointments and send reminders def check_and_send_reminders(): current_time = datetime.datetime.now() reminder_time = current_time + datetime.timedelta(hours=24) for patient, date_time_str in patients.items(): date_time = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S') if date_time < reminder_time: send_reminder(patient + '@example.com', date_time) patients.pop(patient) # Schedule the function to run every day import schedule import time schedule.every().day.at("00:00").do(check_and_send_reminders) while True: schedule.run_pending() time.sleep(1)
Скрипт, который автоматизирует процесс записи и напоминания для пациентов
schedule
18.09.2023