fin_connexion: going to prod
This commit is contained in:
parent
b6d3917ef7
commit
9faaf0d6b6
3 changed files with 74 additions and 41 deletions
|
@ -55,20 +55,15 @@ FILTRE_TPL = u"""(&
|
|||
# usage :
|
||||
# datetime.datetime.now(tz)
|
||||
|
||||
c = lc_ldap_readonly()
|
||||
|
||||
# Instant courant: on ne garde que le jour
|
||||
now = datetime.datetime.now()
|
||||
|
||||
# Applique un delta, si spécifié
|
||||
for arg in sys.argv[1:]:
|
||||
if arg.startswith('+'):
|
||||
now += int(arg[1:])*DAY
|
||||
today = now.replace(**ERASE_DAY)
|
||||
print "Nous serons le %s" % today
|
||||
|
||||
def warn(adh, delai):
|
||||
data = {'delai': delai}
|
||||
def warn(mail_conn, adh):
|
||||
fin = min(max(parse_gtf(v.value) for v in adh[l]) \
|
||||
for l in ['finConnexion', 'finAdhesion'] )
|
||||
delai = (fin - datetime.datetime.now(pytz.UTC)).days
|
||||
data = {
|
||||
'delai': delai,
|
||||
'adh': adh,
|
||||
}
|
||||
for l in ['adhesion', 'connexion']:
|
||||
fin = max(parse_gtf(v.value) for v in adh['fin' + l.capitalize()])
|
||||
data['fin_%s' % l] = fin
|
||||
|
@ -80,7 +75,7 @@ def warn(adh, delai):
|
|||
return
|
||||
data.update({'To': To, 'From': From})
|
||||
mailtxt = mail_module.generate('fin_connexion', data)
|
||||
print mailtxt
|
||||
mail_conn.sendmail(From, [To], mailtxt.as_string())
|
||||
|
||||
|
||||
def compute_fin_connexion(adh):
|
||||
|
@ -123,7 +118,7 @@ def brief(c, debut, fin):
|
|||
print "%r %s %s;%s" % (adh, adh.dn.split(',', 1)[0], f_con, f_adh)
|
||||
return to_warn
|
||||
|
||||
def prev(c, date):
|
||||
def prev_calendar(c, date):
|
||||
"""Prévisualise l'expiration des connexions sur le mois courant"""
|
||||
month = date.month
|
||||
year = date.year
|
||||
|
@ -139,37 +134,72 @@ def prev(c, date):
|
|||
date = compute_fin_connexion(adh)
|
||||
by_day[date.day] += 1
|
||||
|
||||
spaces = 3
|
||||
days = ['L', 'M', 'Me', 'J', 'V', 'S', 'D']
|
||||
print " ".join(d + ' '*(spaces-len(d)) for d in days)
|
||||
yield ['L', 'M', 'Me', 'J', 'V', 'S', 'D']
|
||||
l = []
|
||||
for d in cal.itermonthdays(year, month):
|
||||
if not d:
|
||||
item = ""
|
||||
elif not by_day[d]:
|
||||
item = "."
|
||||
item = None
|
||||
else:
|
||||
item = str(by_day[d])
|
||||
l.append(item + ' '*(spaces-len(item)))
|
||||
item = by_day[d]
|
||||
l.append(item)
|
||||
if len(l) == 7:
|
||||
print " ".join(l)
|
||||
yield l
|
||||
l = []
|
||||
if l:
|
||||
print " ".join(l)
|
||||
yield l+(7-len(l))*[None]
|
||||
|
||||
|
||||
# zone de test
|
||||
#warn(c.search(u'aid=4281')[0], 7)
|
||||
prev(c, today)
|
||||
def ascii_calendar(calendar):
|
||||
spaces = 3
|
||||
def pretty_day(x):
|
||||
if x is None:
|
||||
return ''
|
||||
if x == 0:
|
||||
return '.'
|
||||
return str(x)
|
||||
def spaced(x):
|
||||
v = pretty_day(x)
|
||||
return v + (spaces-len(v))*' '
|
||||
|
||||
# Plusieurs type d'execution:
|
||||
# * Manuel (préventif): avertit d'une déco dans moins d'un mois
|
||||
# select(c, today, today+30*DAY)
|
||||
# * Quotidien (préventif) : avertit d'une déco dans moins d'un mois
|
||||
# select(c, today+(30-1)*DAY, today+30*DAY)
|
||||
# * Quotidien (last chance): avertit d'une déco dans moins de 4 jours
|
||||
# (l'idée, c'est qu'il y a toujours une perm entre les deux)
|
||||
# select(c, today+(4-1)*DAY, today+4*DAY)
|
||||
for line in calendar:
|
||||
print ' '.join(map(spaced, line))
|
||||
|
||||
def batch_warn(liste):
|
||||
with mail_module.ServerConnection() as mail_conn:
|
||||
for adh in liste:
|
||||
warn(mail_conn, adh)
|
||||
|
||||
if __name__ == '__main__':
|
||||
db = lc_ldap_readonly()
|
||||
|
||||
now = datetime.datetime.now()
|
||||
args = sys.argv[1:]
|
||||
today = now.replace(**ERASE_DAY)
|
||||
for arg in args:
|
||||
# Applique un delta, si spécifié
|
||||
if arg.startswith('+'):
|
||||
now += int(arg[1:])*DAY
|
||||
print "Nous serons le %s" % today
|
||||
|
||||
if '--preventif' in args:
|
||||
# * Manuel (préventif): avertit d'une déco dans moins d'un mois
|
||||
liste = select(db, today, today+30*DAY)
|
||||
print "Va envoyer %d mails. Appuyer sur entrée." % len(liste)
|
||||
raw_input()
|
||||
batch_warn(liste)
|
||||
if '--daily' in args:
|
||||
# * Quotidien (préventif) : avertit d'une déco dans moins d'un mois
|
||||
liste = select(db, today+(30-1)*DAY, today+30*DAY)
|
||||
batch_warn(liste)
|
||||
if '--daily-last-chance' in args:
|
||||
# * Quotidien (préventif) : avertit d'une déco dans moins de 4 jours
|
||||
# but: prévenir une dernière fois avant la prochaine perm
|
||||
liste = select(db, today+(4-1)*DAY, today+4*DAY)
|
||||
batch_warn(liste)
|
||||
if '--prev' in args:
|
||||
ascii_calendar(prev_calendar(db, today))
|
||||
|
||||
# TODO
|
||||
# * Mensuel: avertit les cableurs des connexions à expiration dans le mois
|
||||
# prochain
|
||||
# select(c, first_day, last_day+DAY)
|
||||
|
|
|
@ -1 +1 @@
|
|||
{{To}}
|
||||
"{{ adh|name }}" <{{To}}>
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
Cher adhérent du Crans,
|
||||
|
||||
Nous t'envoyons ce message pour t'informer que ta connexion arrive à
|
||||
expiration dans moins de {{ delai }} jours. En effet, elle est valable jusqu'au
|
||||
{{ fin_connexion|date }}, sous réserve d'adhésion, s'achevant le
|
||||
{{ fin_adhesion|date }}.
|
||||
|
||||
expiration dans moins de {{ delai }} jours.{% if fin_connexion > fin_adhesion %}
|
||||
En effet, ton adhésion annuelle s'achève le {{ fin_adhesion|date}} même
|
||||
si les frais de connexion restent acquis jusqu'au {{ fin_connexion|date }}.
|
||||
{% else %}
|
||||
En effet, les frais de connexion sont valables jusqu'au {{ fin_connexion|date }}
|
||||
et ton adhésion annuelle s'achève le {{ fin_adhesion|date }}.
|
||||
{% endif %}
|
||||
Pour réadhérer ou prolonger ta connexion, tu peux nous retrouver
|
||||
lors d'une de nos permanences. Pour rappel, elles ont lieu du lundi au vendredi,
|
||||
de 12h30 à 13h30 et de 18h30 à 20h30, *sauf le mardi soir*.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue