From a68f8f68edd53acae2f6e28f9f048eea1f91f4c0 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 19 Feb 2022 23:27:19 -0500 Subject: [PATCH] Changed to send reminders daily until completed. Added check to limit notifications from going out once per day. Added second scheduler task to reset notification sent status 1 hour after they are sent. --- app.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 2209709..09ca5b2 100644 --- a/app.py +++ b/app.py @@ -8,7 +8,9 @@ from flask_apscheduler import APScheduler # Set to True to simplify testing TESTING = False - +notificationHour = 10 +textSent = False +emailSent = False class Config: SCHEDULER_API_ENABLED = True @@ -63,39 +65,56 @@ SettingsMetadata.__table__.create(bind=engine, checkfirst=True) Session = sessionmaker(bind=engine) -@scheduler.task('cron', id='send_notifications', hour='10') +@scheduler.task('cron', id='send_notifications', hour=notificationHour) def Checknotifications(): session = Session() + global textSent + global emailSent nextFeed = session.query(Dates).filter_by(dateTypeID=3).first().dateValue nextClean = session.query(Dates).filter_by(dateTypeID=5).first().dateValue clean = False today = datetime.date.today() - if nextClean == today or TESTING is True: + if nextClean <= today or TESTING is True: clean = True else: clean = False - # Check if notififcations need to be sent out - if nextFeed == today or TESTING is True: + # Check if notifications need to be sent out + if nextFeed <= today or TESTING is True: # Check what notifications should be sent out grab the grab relevant contact info and pass it to the appropriate # notification method notifications = {'text': session.query(Settings).filter_by(settingType=1).first().settingValue, 'email': session.query(Settings).filter_by(settingType=2).first().settingValue} - if notifications['text']: + if notifications['text'] and textSent is False: contact = session.query(Settings).filter_by(settingType=4).first().settingValue sendNotifications.sendText(contact, clean) - if notifications['email']: + textSent = True + if notifications['email'] and emailSent is False: contact = session.query(Settings).filter_by(settingType=5).first().settingValue sendNotifications.sendEmail(contact, clean) print('sent any selected notifications') # print(today) # print(nextFeed) + if TESTING is True: + resetNotifcations() else: print('Not time to Send') session.close() +@scheduler.task('cron', id='reset_notifications', hour=notificationHour+1) +def resetNotifcations(): + global textSent + global emailSent + + if textSent is True: + textSent = False + if emailSent is True: + emailSent = False + return + + scheduler.start() # If in testing mode reschedule the notification check to run every minute