2024-01-08 20:03:51 +00:00
|
|
|
# this Class is for the scheduler
|
|
|
|
#this class will have a function that locates the upcomming events Using the Event service.
|
|
|
|
from services.EventService import EventService
|
2024-01-09 09:01:39 +00:00
|
|
|
from services.UserService import UserService
|
|
|
|
from models import UserEventAssociation, db
|
2024-01-08 20:03:51 +00:00
|
|
|
|
2024-01-09 08:23:57 +00:00
|
|
|
class EventNotifyerService:
|
2024-01-08 20:03:51 +00:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
2024-01-09 09:01:39 +00:00
|
|
|
|
2024-01-09 08:25:38 +00:00
|
|
|
def notifyUpcommingEvents():
|
2024-01-09 09:01:39 +00:00
|
|
|
events = EventService.get_upcoming_events()
|
|
|
|
for event in events:
|
|
|
|
users = UserService.get_users_with_same_location_but_not_been_notifyed(event['location'])
|
|
|
|
if not users:
|
|
|
|
print("No user to notify")
|
|
|
|
continue
|
|
|
|
for user in users:
|
|
|
|
print("Found user to notify:", user)
|
|
|
|
if notify_user(user['email'], event):
|
|
|
|
user_event_association = UserEventAssociation(
|
|
|
|
user_id=user['id'],
|
|
|
|
event_id=event['id']
|
|
|
|
)
|
|
|
|
db.session.add(user_event_association)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
def notify_user(userEmail, event):
|
2024-01-09 16:25:18 +00:00
|
|
|
try:
|
|
|
|
print("User:", userEmail, "Event:", event)
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
print("Error printing user and event")
|
|
|
|
return False
|
2024-01-09 09:01:39 +00:00
|
|
|
|
|
|
|
|