Coverage for app/scripts/send_event_reminder_emails.py: 91%
33 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-25 18:59 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-25 18:59 +0000
1import os
2import socket
4from app import app
5from app.logic.emailHandler import EmailHandler
6from app.logic.events import getTomorrowsEvents
7from app.models.term import Term
8from app.models.user import User
9from app.models.emailTemplate import EmailTemplate
11def sendEventReminderEmail(events):
12 """Function that sends an email for every event occuring the next day"""
13 if not len(events):
14 return 0
16 counter = 0
17 currentTerm = Term.get(isCurrentTerm=1)
19 template = EmailTemplate.get(purpose = "Reminder")
20 templateSubject = template.subject
21 templateBody = template.body
22 for event in events:
23 programId = event.program
24 emailData = {"eventID":event.id, # creates the email data
25 "programID":programId,
26 "term":currentTerm.id,
27 "emailSender":"Reminder Automation",
28 "sender_name":"Reminder Automation",
29 "templateIdentifier":"Reminder",
30 "recipientsCategory":"Interested",
31 "subject":templateSubject,
32 "body":templateBody}
33 sendEmail = EmailHandler(emailData, gethost())
34 sendEmail.send_email()
35 counter += 1
36 return counter
38def main():
39 sendEventReminderEmail(getTomorrowsEvents())
41def gethost():
42 host = "localhost:8080"
43 if os.getenv('IP'):
44 host = os.getenv('IP') + ":" + os.getenv('PORT')
45 else:
46 host = socket.gethostbyname(socket.gethostname()) + ":8080"
48 if app.env == "production":
49 host = socket.getfqdn()
51 return host
53# main()