summaryrefslogtreecommitdiff
path: root/workshop_app/reminder_script.py
blob: 4c4350cd9725ec8ba2505e7e1f74779a7656961f (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
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
			)

	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
			)

send_email()