From: Arnaud Delcasse Date: Wed, 12 Sep 2012 06:07:55 +0000 (+0200) Subject: Remind nonvoters X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/Special:BookSources/%40%20%27config_titre_base_sup%27%20=%3E%20%27Declaration%20of%20an%20additional%20database%27%2C%20%27config_titre_base_sup_choix%27%20=%3E%20%27Choose%20an%20additional%20database%27%2C%20%27connexion_ldap%27%20=%3E%20%27Connection:%27%2C-%27copier_en_local%27%20=%3E%20%27Copy%20to%20local%20site%27%2C%20%27creer_et_associer_un_auteur%27%20=%3E%20%27Create%20and%20associate%20an%20author%27%2C-%27creer_et_associer_une_rubrique%27%20=%3E%20%27Create%20and%20link%20a%20section%27%2C%20%20/%20D%20%27date_mot_heures%27%20=%3E%20%27H%27%2C%40%40%20-141%2C7%20%20113%2C6%20%40%40%20Do%20not%20submit%20this%20import%20request.%3Cp%3EFor%20more%20information%2C%20please%20see%20%3Ca%20href=?a=commitdiff_plain;h=ed210a3988c9182f818221bbea7d63346bb2d3c5;p=cavote.git Remind nonvoters --- diff --git a/reminder.py b/reminder.py new file mode 100644 index 0000000..5b66d8f --- /dev/null +++ b/reminder.py @@ -0,0 +1,45 @@ +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.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 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): + 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 = "http://vote.ffdn.org/vote/%d" % 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 :", + link, + "", + "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) + server.quit()