Commit ed210a39 authored by Arnaud Delcasse's avatar Arnaud Delcasse

Remind nonvoters

parent 1cff7e92
import os
import hashlib
import smtplib
import string
from datetime import time, date, timedelta
from settings import *
import sqlite3
conn = sqlite3.connect(DATABASE)
c = conn.cursor()
for vote in c.execute('select id, id_group, date_end, title from votes where is_open=1 and is_terminated=0'):
print vote[0]
date_end_vote = date.fromtimestamp(vote[2])
date_today =
date_begin_reminder = date_end_vote + timedelta(days=-3)
if date_today >= date_begin_reminder and date_today <= date_end_vote:
voting_group = (vote[1],)
for user in c.executequery('select,, from users join user_group on where user_group.id_group = ?', voting_group):
userchoice_request = (user[0], vote[1],)
userchoice = c.executequery('select * from user_choice where id_user = ? and id_vote = ?', userchoice_request)
if userchoice is None:
#user didn't vote yet
link = "" % vote[0]
BODY = string.join((
"From: %s" % EMAIL,
"To: %s" % user[1],
"Subject: [Cavote] Vote reminder",
"Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'),
"X-Mailer: %s" % VERSION,
"A vote concerns you and is going to finish on %s : %s" % vote[2]%vote[3],
"This link will bring you to the form where you will be able to participate :",
"If you think this mail is not for you, please ignore and delete it."
), "\r\n")
server = smtplib.SMTP(SMTP_SERVER)
server.sendmail(EMAIL, user[1], BODY)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment