mirror of
https://github.com/sartography/uva-covid19-testing-communicator.git
synced 2025-02-24 04:48:05 +00:00
setting up scheduler to allow sending notifications between 1 and pm.
This commit is contained in:
parent
43df690e1c
commit
5504c021bc
@ -1,3 +1,7 @@
|
||||
from datetime import datetime
|
||||
|
||||
import pytz
|
||||
|
||||
from communicator import db, app
|
||||
import time
|
||||
import atexit
|
||||
@ -7,12 +11,26 @@ from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from communicator.api import admin
|
||||
|
||||
|
||||
def within_notification_window(self):
|
||||
"""Where 'reasaonable' is between 8am and 10pm. """
|
||||
tz = pytz.timezone('US/Eastern')
|
||||
now = (datetime.now(tz))
|
||||
one_pm = (datetime.now(tz).replace(hour=13, minute=0, second=0, microsecond=0))
|
||||
two_pm = (datetime.now(tz).replace(hour=14, minute=0, second=0, microsecond=0))
|
||||
return one_pm <= now <= two_pm
|
||||
|
||||
|
||||
def update_and_notify():
|
||||
with app.app_context():
|
||||
if app.config['RUN_SCHEDULED_TASKS']:
|
||||
admin._update_data()
|
||||
admin._notify_by_email()
|
||||
admin._notify_by_text()
|
||||
if within_notification_window():
|
||||
app.logger.info("Within Notification Window, sending messages.")
|
||||
admin._notify_by_email()
|
||||
admin._notify_by_text()
|
||||
else:
|
||||
app.logger.info("Not within the notification window, not sending messages.")
|
||||
|
||||
|
||||
if app.config['RUN_SCHEDULED_TASKS']:
|
||||
scheduler = BackgroundScheduler()
|
||||
|
Loading…
x
Reference in New Issue
Block a user