-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystemeVote.py
100 lines (77 loc) · 3.16 KB
/
SystemeVote.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#coding:utf-8
'''
Created on 23 oct. 2023
@author: Louis-Alain
'''
import os
from cryptography.fernet import Fernet
import SystemeEnvoiCourriels
import pandas
class SystemeVote(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
self.mPath=os.path.dirname(os.path.abspath(__file__))
self.mFichierBrutMembres="Membres2023.csv"
self.mFichierCourriels="CourrielsNoms.csv"
self.mFichierCourrielsClefs="CourrielsNomsClefs.csv"
self.mFichierClef="MotDePasse.txt"
self.mClef=""
self.mCodes=dict()
def GenererClef(self):
wClefTexte=Fernet.generate_key()
self.mClef=Fernet(wClefTexte)
with open(self.mPath+"\\"+self.mFichierClef,'w') as wFich:
wFich.write("%s"%wClefTexte)
wFich.close()
def ChargerClef(self):
self.mClef=""
with open(self.mPath+"\\"+self.mFichierClef,'r') as wFich:
self.mClef=bytes(wFich.readline(),"utf-8")[2:-1]
wFich.close()
def ImporterCourrielsValides(self):
wLignesSales=list()
wCsvPd=pandas.read_csv(self.mPath+"\\"+self.mFichierBrutMembres)
wLignesReduites=list()
wMembresValides=wCsvPd.loc[wCsvPd['Statut membre'] == "En règle"]
wColonnesReduites=wMembresValides[['x','Courriel']]
wColonnesReduites=wColonnesReduites.rename(columns={"x": "Prénom"})
wUniques=wColonnesReduites["Courriel"].unique()
wDf=pandas.DataFrame(data=None,columns=["Prénom","Courriel","Clef"])
for wU in wUniques:
wMembreDoublon=wColonnesReduites.loc[wCsvPd['Courriel'] == wU]
wMembre=wMembreDoublon.iloc[0]
#wMembre["Prénom"]=wMembre["Prénom"].capitalize()
wDf=wDf.append(wMembre)
wDf.to_csv(self.mPath+"\\"+self.mFichierCourriels)
return wDf
def SauverCodes(self,iListe):
pass
def GetCodes(self):
pass
def GenererCodes(self):
# Charger le mot de passe
self.ChargerClef()
wMembres=self.ImporterCourrielsValides()
# Créer les codes
for index, row in wMembres.iterrows():
wCourriel=row["Courriel"]
wClefCourrielLong=Fernet(self.mClef).encrypt_at_time(bytes(wCourriel,'utf-8'),0)
wClefCourriel=str(wClefCourrielLong[-10:])[2:-2]
row["Clef"]=wClefCourriel
wMembres.to_csv(self.mPath+"\\"+self.mFichierCourrielsClefs)
def EnvoyerCourriels(self):
wSysCourriels=SystemeEnvoiCourriels.SystemeEnvoiCourriels()
# Ouvrir la liste de codes (avec courriels)
wCsvPd=pandas.read_csv(self.mPath+"\\"+self.mFichierCourrielsClefs)
# Envoyer un courriel par adresse
for index, row in wCsvPd.iterrows():
wCourriel=row["Courriel"]
wClef=row["Clef"]
wPrenom=row["Prénom"]
wLien="https://s.surveylegend.com/-NhZqhYQQx7v1QHEJoXy?courriel=%s&clef=%s"%(wCourriel,wClef)
wSysCourriels.EnvoiSondage(wPrenom, wCourriel, wLien)