forked from AFPy/gestion
Ajout des scripts pour les adhérents
This commit is contained in:
parent
6e997008f3
commit
d3f74b229e
|
@ -0,0 +1,83 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import csv
|
||||||
|
from datetime import date, timedelta
|
||||||
|
from getpass import getpass
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
LOGIN = 'tresorerie@afpy.org'
|
||||||
|
CAMPAIGN_IDS = (14589, 31115)
|
||||||
|
|
||||||
|
|
||||||
|
def get_members(year, password=None, output_format='csv'):
|
||||||
|
if not password:
|
||||||
|
password = getpass('Mot de passe HelloAsso : ')
|
||||||
|
|
||||||
|
session = requests.Session()
|
||||||
|
session.get(
|
||||||
|
'https://www.helloasso.com/utilisateur/authentificate',
|
||||||
|
json={
|
||||||
|
'currentUrl': 'https://helloasso.com/',
|
||||||
|
'email': LOGIN,
|
||||||
|
'password': password,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
start = date(year, 1, 1)
|
||||||
|
end = date(year + 1, 1, 1) - timedelta(days=1)
|
||||||
|
|
||||||
|
start_str = f'{start.day}/{start.month}/{start.year}'
|
||||||
|
end_str = f'{end.day}/{end.month}/{end.year}'
|
||||||
|
|
||||||
|
for campaign_id in CAMPAIGN_IDS:
|
||||||
|
url = (
|
||||||
|
'https://www.helloasso.com/admin/handler/reports.ashx?'
|
||||||
|
'type=Details&format=Csv&'
|
||||||
|
f'id_adh={campaign_id}&from={start_str}&to={end_str}&'
|
||||||
|
'includeSubpages=1&period=MONTH&domain=HelloAsso&trans=Adhesions&'
|
||||||
|
)
|
||||||
|
response = session.get(url)
|
||||||
|
|
||||||
|
rows = csv.reader(StringIO(response.text), delimiter=';')
|
||||||
|
header = next(rows)
|
||||||
|
name_index = header.index('Nom')
|
||||||
|
firstname_index = header.index('Prénom')
|
||||||
|
email_index = header.index('Email')
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
if output_format == 'dict':
|
||||||
|
yield {
|
||||||
|
'name': row[name_index],
|
||||||
|
'firstname': row[firstname_index],
|
||||||
|
'email': row[email_index],
|
||||||
|
}
|
||||||
|
elif output_format == 'csv':
|
||||||
|
yield ','.join(
|
||||||
|
row[index] for index in
|
||||||
|
(name_index, firstname_index, email_index)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
password = getpass('Mot de passe HelloAsso : ')
|
||||||
|
|
||||||
|
print('')
|
||||||
|
|
||||||
|
print('Membres de l’année dernière')
|
||||||
|
print('===========================')
|
||||||
|
print('')
|
||||||
|
rows = get_members(date.today().year - 1, password)
|
||||||
|
for i, row in enumerate(rows):
|
||||||
|
print(f'{i + 4: 3}', row)
|
||||||
|
|
||||||
|
print('')
|
||||||
|
|
||||||
|
print('Membres de cette année')
|
||||||
|
print('======================')
|
||||||
|
print('')
|
||||||
|
rows = get_members(date.today().year, password)
|
||||||
|
for i, row in enumerate(rows):
|
||||||
|
print(f'{i + 4: 3}', row)
|
|
@ -0,0 +1,94 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import smtplib
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import traceback
|
||||||
|
from datetime import date
|
||||||
|
from email.message import EmailMessage
|
||||||
|
from getpass import getpass
|
||||||
|
|
||||||
|
from helloasso import get_members
|
||||||
|
|
||||||
|
|
||||||
|
HOST = 'mail.afpy.org'
|
||||||
|
PORT = 587
|
||||||
|
SUBJECT = 'Campagne de cotisation AFPy'
|
||||||
|
TEMPLATE = '''Bonjour {firstname} {name},
|
||||||
|
|
||||||
|
Vous recevez ce courriel en tant que membre de l'Association Francophone
|
||||||
|
Python.
|
||||||
|
|
||||||
|
Nos scripts Python nous ont informés que vous n'étiez pas à jour de votre
|
||||||
|
cotisation.
|
||||||
|
|
||||||
|
Maintenir votre cotisation à jour vous permet de prendre part aux votes lors
|
||||||
|
des assembles générales et de soutenir l'action de l'association,
|
||||||
|
financièrement et moralement.
|
||||||
|
|
||||||
|
Voici un exemple des ralisations de l'AFPy ces dernières années :
|
||||||
|
|
||||||
|
- organisation des confrences PyConFr,
|
||||||
|
- partenariat avec la confrence PyData,
|
||||||
|
- financement ou organisation de divers ateliers Python (Django Girl, Django
|
||||||
|
Carrot. Workshop Django…),
|
||||||
|
- traduction en français de la documentation Python,
|
||||||
|
- mise en place de rencontres locales (Lyon, Pau, Nantes, Grenoble, Paris,
|
||||||
|
Rennes…).
|
||||||
|
|
||||||
|
La cotisation annuelle de l'AFPy est de 20 €. Le taux réduit de 10 € s'applique
|
||||||
|
aux personnes ayant des revenus modestes.
|
||||||
|
|
||||||
|
Vous pouvez payer votre cotisation en ligne à l'adresse suivante :
|
||||||
|
|
||||||
|
https://www.helloasso.com/associations/afpy/adhesions/
|
||||||
|
|
||||||
|
En attendant de recevoir votre cotisation, nous vous souhaitons une bonne
|
||||||
|
journée pleine de Python !
|
||||||
|
|
||||||
|
--
|
||||||
|
Association Francophone Python
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
smtp_login = getpass('Identifiant SMTP : ')
|
||||||
|
smtp_password = getpass('Mot de passe SMTP : ')
|
||||||
|
hello_password = getpass('Mot de passe HelloAsso : ')
|
||||||
|
|
||||||
|
print()
|
||||||
|
print('Récupération des membres…')
|
||||||
|
print()
|
||||||
|
|
||||||
|
old_members = get_members(
|
||||||
|
date.today().year - 1, hello_password, output_format='dict')
|
||||||
|
new_members_emails = {
|
||||||
|
member['email'] for member in
|
||||||
|
get_members(date.today().year, hello_password, output_format='dict')}
|
||||||
|
members = [
|
||||||
|
member for member in old_members
|
||||||
|
if member['email'] not in new_members_emails]
|
||||||
|
|
||||||
|
members = [{'firstname': 'Guillaume', 'name': 'Ayoub', 'email': 'xovni@wanadoo.fr'}]
|
||||||
|
print(f'Envoi du message à {len(members)} personnes dans 10 secondes !')
|
||||||
|
print()
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
for member in members:
|
||||||
|
message = EmailMessage()
|
||||||
|
message.set_content(TEMPLATE.format(**member))
|
||||||
|
message['Subject'] = SUBJECT
|
||||||
|
message['From'] = f'Association Francophone Python <{smtp_login}>'
|
||||||
|
message['To'] = [member['email']]
|
||||||
|
|
||||||
|
print(f'Envoi à {member["email"]}')
|
||||||
|
|
||||||
|
afpy_smtp = smtplib.SMTP(host=HOST, port=PORT)
|
||||||
|
afpy_smtp.starttls()
|
||||||
|
afpy_smtp.login(smtp_login, smtp_password)
|
||||||
|
try:
|
||||||
|
afpy_smtp.send_message(message)
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc(file=sys.stderr)
|
||||||
|
afpy_smtp.quit()
|
||||||
|
time.sleep(1)
|
Loading…
Reference in New Issue