main.py 1.42 KB
Newer Older
Grizzly's avatar
Grizzly committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/usr/bin/env python3
from configparser import ConfigParser
import socket

from re2oapi import Re2oAPIClient
from django.core.mail import send_mail
from django.template import loader, Context

from pprint import pprint

config = ConfigParser()
config.read('config.ini')

api_hostname = config.get('Re2o', 'hostname')
api_password = config.get('Re2o', 'password')
api_username = config.get('Re2o', 'username')

api_client = Re2oAPIClient(api_hostname,api_username,api_password)

client_hostname = socket.gethostname().split('.',1)[0]

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')

    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)
            )