forked from osamak/rlugroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_survey.py
33 lines (24 loc) · 978 Bytes
/
send_survey.py
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
# -*- coding: utf-8 -*-
import datetime
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
from django.conf import settings
from events.models import Attendee, Event
from post_office import mail
queued_addresses = [] # To aviod sending an email twice.
event_pk = int(sys.argv[1])
survey_url = sys.argv[2]
event = Event.objects.get(pk=event_pk)
print u"Surveing {0} attendees with: {1}".format(event.name, survey_url).encode('utf-8')
for attendee in event.attendee_set.filter(is_counted=True):
if attendee.email in queued_addresses:
continue
else:
queued_addresses.append(attendee.email)
print u"Queuing the survey to {0}".format(attendee.email).encode('utf-8')
mail.send([attendee.email], settings.EVENT_FROM_EMAIL,
template='event_survey',
context={'event': event,'attendee': attendee,
'survey_url': survey_url})