1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2025-04-27 09:52:35 +00:00

Compare commits

..

3 Commits

Author SHA1 Message Date
hugoooo
e0b623d5a4 Merge branch 'notes_report' into 'master'
send summary script

See merge request bde/nk20-scripts!5
2025-03-06 11:28:48 +01:00
thomasl
3dd5f6e3e0 Extend the possibility to send the list by email to the other newsletters 2025-03-04 16:50:49 +01:00
thomasl
735d90e482 Add an option to send the list to an email 2025-03-04 16:39:04 +01:00

View File

@ -22,6 +22,8 @@ class Command(BaseCommand):
'events mailing list.')
parser.add_argument('--years', '-y', type=int, default=0,
help='Select the cumulative registred users of a membership from years ago. 0 means the current users')
parser.add_argument('--email', '-e', type=str, default="",
help='Put the email supposed to receive the emails of the mailing list (only for art). If nothing is put, the script will just print the emails.')
def handle(self, *args, **options):
# TODO: Improve the mailing list extraction system, and link it automatically with Mailman.
@ -46,36 +48,89 @@ class Command(BaseCommand):
self.stdout.write(club.email)
return
# Get the list of mails that want to be registered to the events mailing list.
# Get the list of mails that want to be registered to the events mailing listn, as well as the number of mails.
# Print it or send it to the email provided by the user.
# Don't filter to valid members, old members can receive these mails as long as they want.
if options["type"] == "events":
for user in User.objects.filter(profile__ml_events_registration=options["lang"]).all():
self.stdout.write(user.email)
nb=0
if options["email"] == "":
for user in User.objects.filter(profile__ml_events_registration=options["lang"]).all():
self.stdout.write(user.email)
nb+=1
self.stdout.write(str(nb))
else :
emails = []
for user in User.objects.filter(profile__ml_events_registration=options["lang"]).all():
emails.append(user.email)
nb+=1
subject = "Liste des abonnés à la newsletter BDE"
message = (
f"Voici la liste des utilisateurs abonnés à la newsletter BDE:\n\n"
+ "\n".join(emails)
+ f"\n\nTotal des abonnés : {nb}"
)
from_email = "Note Kfet 2020 <notekfet2020@crans.org>"
recipient_list = [options["email"]]
send_mail(subject, message, from_email, recipient_list)
return
if options["type"] == "art":
nb=0
emails = []
for user in User.objects.filter(profile__ml_art_registration=True).all():
# self.stdout.write(user.email)
emails.append(user.email)
nb+=1
# self.stdout.write(str(nb))
subject = "Liste des abonnés à la newsletter BDA"
message = (
f"Voici la liste des utilisateurs abonnés à la newsletter BDA:\n\n"
+ "\n".join(emails)
+ f"\n\nTotal des abonnés : {nb}"
)
from_email = "Note Kfet 2020 <notekfet2020@crans.org>"
recipient_list = ["bda.ensparissaclay@gmail.com"]
if options["email"] == "":
for user in User.objects.filter(profile__ml_art_registration=True).all():
self.stdout.write(user.email)
nb+=1
self.stdout.write(str(nb))
send_mail(subject, message, from_email, recipient_list)
else :
emails = []
for user in User.objects.filter(profile__ml_art_registration=True).all():
emails.append(user.email)
nb+=1
subject = "Liste des abonnés à la newsletter BDA"
message = (
f"Voici la liste des utilisateurs abonnés à la newsletter BDA:\n\n"
+ "\n".join(emails)
+ f"\n\nTotal des abonnés : {nb}"
)
from_email = "Note Kfet 2020 <notekfet2020@crans.org>"
recipient_list = [options["email"]]
send_mail(subject, message, from_email, recipient_list)
return
if options["type"] == "sport":
for user in User.objects.filter(profile__ml_sport_registration=True).all():
self.stdout.write(user.email)
nb=0
if options["email"] == "":
for user in User.objects.filter(profile__ml_sport_registration=True).all():
self.stdout.write(user.email)
nb+=1
self.stdout.write(str(nb))
else :
emails = []
for user in User.objects.filter(profile__ml_sport_registration=True).all():
emails.append(user.email)
nb+=1
subject = "Liste des abonnés à la newsletter BDS"
message = (
f"Voici la liste des utilisateurs abonnés à la newsletter BDS:\n\n"
+ "\n".join(emails)
+ f"\n\nTotal des abonnés : {nb}"
)
from_email = "Note Kfet 2020 <notekfet2020@crans.org>"
recipient_list = [options["email"]]
send_mail(subject, message, from_email, recipient_list)
return