Remind nonvoters
[cavote.git] / reminder.py
1 import os
2 import hashlib
3 import smtplib
4 import string
5 from datetime import time, date, timedelta
6
7 from settings import *
8
9
10 import sqlite3
11
12 conn = sqlite3.connect(DATABASE)
13 c = conn.cursor()
14
15 for vote in c.execute('select id, id_group, date_end, title from votes where is_open=1 and is_terminated=0'):
16 print vote[0]
17 date_end_vote = date.fromtimestamp(vote[2])
18 date_today = date.today
19 date_begin_reminder = date_end_vote + timedelta(days=-3)
20
21 if date_today >= date_begin_reminder and date_today <= date_end_vote:
22 voting_group = (vote[1],)
23 for user in c.executequery('select user.id, users.email, users.name from users join user_group on users.id=user_group.id_user where user_group.id_group = ?', voting_group):
24 userchoice_request = (user[0], vote[1],)
25 userchoice = c.executequery('select * from user_choice where id_user = ? and id_vote = ?', userchoice_request)
26 if userchoice is None:
27 #user didn't vote yet
28 link = "http://vote.ffdn.org/vote/%d" % vote[0]
29 BODY = string.join((
30 "From: %s" % EMAIL,
31 "To: %s" % user[1],
32 "Subject: [Cavote] Vote reminder",
33 "Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'),
34 "X-Mailer: %s" % VERSION,
35 "",
36 "A vote concerns you and is going to finish on %s : %s" % vote[2]%vote[3],
37 "",
38 "This link will bring you to the form where you will be able to participate :",
39 link,
40 "",
41 "If you think this mail is not for you, please ignore and delete it."
42 ), "\r\n")
43 server = smtplib.SMTP(SMTP_SERVER)
44 server.sendmail(EMAIL, user[1], BODY)
45 server.quit()