Reecriture partielle, utilisation d'une api mail custom
This commit is contained in:
parent
c4d28c9781
commit
33acc6c4d5
2 changed files with 39 additions and 36 deletions
53
main.py
53
main.py
|
@ -2,9 +2,9 @@
|
|||
from configparser import ConfigParser
|
||||
import socket
|
||||
|
||||
from re2oapi import Re2oAPIClient
|
||||
from django.core.mail import send_mail
|
||||
from django.template import loader, Context
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from re2oapi import Re2oAPIClient, ApiSendMail
|
||||
|
||||
from pprint import pprint
|
||||
import sys
|
||||
|
@ -18,37 +18,46 @@ api_username = config.get('Re2o', 'username')
|
|||
|
||||
api_client = Re2oAPIClient(api_hostname,api_username,api_password)
|
||||
|
||||
api_mailserver = config.get('Mail', 'mailserver')
|
||||
api_port = config.get('Mail', 'port')
|
||||
|
||||
api_sendmail = ApiSendMail(api_mailserver, api_port)
|
||||
|
||||
client_hostname = socket.gethostname().split('.',1)[0]
|
||||
|
||||
for arg in sys.argv:
|
||||
if arg=="--force":
|
||||
notif_end_adhesion(api_client)
|
||||
# Création de l'environnement Jinja
|
||||
ENV = Environment(loader=FileSystemLoader('.'))
|
||||
|
||||
def notif_end_adhesion(api_client):
|
||||
asso_options = api_client.list("preferences/assooption")
|
||||
from_mail = api_client.list("preferences/generaloption")["email_from"]
|
||||
template = loader.get_template('email_fin_adhesion')
|
||||
asso_options = api_client.view("preferences/assooption/")
|
||||
general_options = api_client.view("preferences/generaloption/")
|
||||
template = ENV.get_template("templates/email_fin_adhesion")
|
||||
|
||||
for result in api_client.list("reminder/get-users"):
|
||||
for user in result["users_to_remind"]:
|
||||
context = Context({
|
||||
'nom': user["get_full_name"],
|
||||
'temps': result["days"],
|
||||
'asso_name': asso_options["name"],
|
||||
'link': asso_options["site_url"]
|
||||
})
|
||||
print('mail envoyé à {}, reminder {} days'.format(user["get_full_name"],result["days"]))
|
||||
send_mail("Avis de fin d'adhésion / End of subscription notice",
|
||||
'',
|
||||
from_mail,
|
||||
user["email"],
|
||||
html_message = template.render(context)
|
||||
if "--verbose" in sys.argv:
|
||||
print('Mail envoyé à {}, reminder {} days'.format(user["get_full_name"],result["days"]))
|
||||
reminder_mail = template.render(
|
||||
nom=user["get_full_name"],
|
||||
temps=result["days"],
|
||||
asso_name=asso_options["name"],
|
||||
message=result["message"],
|
||||
link=general_options["main_site_url"])
|
||||
api_sendmail.send_mail(
|
||||
general_options["email_from"],
|
||||
user["get_mail"],
|
||||
"Avis de fin d'adhésion / End of subscription notice",
|
||||
reminder_mail
|
||||
)
|
||||
|
||||
## Manual command
|
||||
if "--force" in sys.argv:
|
||||
notif_end_adhesion(api_client)
|
||||
|
||||
## Automatic regen
|
||||
for service in api_client.list("services/regen/"):
|
||||
if service['hostname'] == client_hostname and \
|
||||
service['service_name'] == 'mail' and \
|
||||
service['service_name'] == 'notif-users' and \
|
||||
service['need_regen']:
|
||||
notif_end_adhesion(api_client)
|
||||
api_client.patch(service['api_url'], data={'need_regen': False})
|
||||
|
|
|
@ -1,27 +1,21 @@
|
|||
<p>Bonjour {{nom}},</p>
|
||||
|
||||
<P>Ton adhésion arrive à son therme dans {{temps}} jours.</P>
|
||||
<p>Ta connexion internet va expirer dans {{temps}} jours.</p>
|
||||
|
||||
{% if online %}
|
||||
<p>Tu peux renouveller ton adhésion en ligne sur <a href"{{link}}">Mon Profil</a>.</p>
|
||||
<p>Tu peux également contacter un membre de {{asso_name}} pour renouveller ton adhésion</p>
|
||||
{% else %}
|
||||
<p>Pour renouveller ton adhésion, contacte un membre de {{asso_name}}.</p>
|
||||
{% endif %}
|
||||
{{message}}
|
||||
|
||||
<p>A bientôt.</p>
|
||||
<p>Tu peux gérer ta connexion en ligne sur <a href={{link}}>Mon profil</a></p>
|
||||
<p>Tu peux bien évidemment également contacter un membre de {{asso_name}} pour renouveller ton adhésion</p>
|
||||
|
||||
<p>A bientôt !</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Hi {{nom}},</p>
|
||||
|
||||
<P>Your subscription comes to an end in {{temps}} days.</P>
|
||||
<p>Your subscription comes to an end in {{temps}} days.</p>
|
||||
|
||||
{% if online %}
|
||||
<p>You can renew it online on <a href"{{link}}">My Profil</a>.</p>
|
||||
<p>You can manage it online on <a href={{link}}>My Profil</a>.</p>
|
||||
<p>You can also contat a member of {{asso_name}} to renew it.</p>
|
||||
{% else %}
|
||||
<p>To renew it, contact a member of {{asso_name}}</p>
|
||||
{% endif %}
|
||||
|
||||
<p>Regards.</p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue