summaryrefslogtreecommitdiff
path: root/workshop_app/reminder_script.py
blob: c30a717af42619f6e54a54da23fcdd96c08ab784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import django
import os
import sys
import datetime as dt
from textwrap import dedent
from django.core.mail import send_mail
from time import sleep

#Setting Up Django Environment Using Existing settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "workshop_portal.settings")
base_path =  os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_path)
django.setup()
#Importing required email credentials
from workshop_portal.settings import (
                    EMAIL_HOST, 
                    EMAIL_PORT, 
                    EMAIL_HOST_USER, 
                    EMAIL_HOST_PASSWORD,
                    EMAIL_USE_TLS,
                    PRODUCTION_URL, 
                    SENDER_EMAIL,
                    ADMIN_EMAIL
                    )
from workshop_app.models import *
from datetime import datetime, date

def send_email():
	upcoming = date.today() + dt.timedelta(days=2)
	upcoming_requested_workshops = RequestedWorkshop.objects.filter(
						requested_workshop_date=upcoming, 
						status='ACCEPTED'
						)

	upcoming_proposed_workshops = ProposeWorkshopDate.objects.filter(
						proposed_workshop_date=upcoming, 
						status='ACCEPTED'
						)
	for w in upcoming_proposed_workshops:
		message = dedent("""\
				Dear {0}, 

				This is to remind you that
				you have a workshop on {1}, 
				for {2}.

				Create Course and Quiz for your workshop.

				Get in touch with your coordinator so that participants
				can be instructed for enrollment.

				Thank You.
				""".format(w.proposed_workshop_instructor.get_full_name(),
					w.proposed_workshop_date, w.proposed_workshop_title))
		send_mail(
			"Gentle Reminder about workshop on {0}"
			.format(w.proposed_workshop_date),message, SENDER_EMAIL,
			[w.proposed_workshop_instructor.email], fail_silently=False
			)

		message = dedent("""\
				Dear {0},

				This is to remind you that
				you have a workshop on {1},
				for {2}.

				You will receive course instructions from our Instructor shortly.

				Thank You.
				""".format(w.proposed_workshop_coordinator.get_full_name(),
					w.proposed_workshop_date, w.proposed_workshop_title))
		send_mail(
			"Gentle Reminder about workshop on {0}"
			.format(w.proposed_workshop_date),message, SENDER_EMAIL,
			[w.proposed_workshop_coordinator.email], fail_silently=False
			)

	for w in upcoming_requested_workshops:
		message = dedent("""\
				Dear {0}, 

				This is to remind you that
				you have a workshop on {1}, 
				for {2}.

				Create Course and Quiz for your workshop.

				Get in touch with your coordinator so that participants
				can be instructed for enrollment.

				Thank You.
				""".format(w.requested_workshop_instructor.get_full_name(),
					w.requested_workshop_date, w.requested_workshop_title))
		send_mail(
			"Gentle Reminder about workshop on {0}"
			.format(w.requested_workshop_date),message, SENDER_EMAIL,
			[w.requested_workshop_instructor.email], fail_silently=False
			)

		message = dedent("""\
				Dear {0},

				This is to remind you that
				you have a workshop on {1},
				for {2}.

				You will receive course instructions from our Instructor shortly.

				Thank You.
				""".format(w.requested_workshop_coordinator.get_full_name(),
					w.requested_workshop_date, w.requested_workshop_title))
		send_mail(
			"Gentle Reminder about workshop on {0}"
			.format(w.requested_workshop_date),message, SENDER_EMAIL,
			[w.requested_workshop_coordinator.email], fail_silently=False
			)

send_email()