|
1
|
import MySQLdb
|
|
2
|
|
|
3
|
|
|
4
|
HOST_SYMPA="sympav6.ac-nice.fr"
|
|
5
|
USER_MYSQL_SYMPA="listaire"
|
|
6
|
PASSWORD_MYSQL_SYMPA="rqp60umh"
|
|
7
|
PORT_SYMPA="3306"
|
|
8
|
DB_SYMPA="sympaV6117"
|
|
9
|
|
|
10
|
|
|
11
|
class MySQLSympaApp():
|
|
12
|
|
|
13
|
def __init__(self, h, u, p, d):
|
|
14
|
self.u = u
|
|
15
|
self.p = p
|
|
16
|
self.h = h
|
|
17
|
self.d = d
|
|
18
|
self.requestlistes = []
|
|
19
|
|
|
20
|
def requete_sympa(self,requete):
|
|
21
|
connectionObject_sympa = MySQLdb.connect(host=self.h, user=self.u, passwd=self.p, db=self.d)
|
|
22
|
c_sympa = connectionObject_sympa.cursor()
|
|
23
|
c_sympa.execute(requete)
|
|
24
|
return c_sympa.fetchall()
|
|
25
|
|
|
26
|
def recupUserSympas(self,mail):
|
|
27
|
listes = []
|
|
28
|
requete = 'SELECT `list_subscriber` FROM `subscriber_table` WHERE `user_subscriber` = "%s";' % (mail)
|
|
29
|
for liste in self.requete_sympa(requete) :
|
|
30
|
listes.append (liste[0]+"@ac-nice.fr")
|
|
31
|
return listes
|
|
32
|
|
|
33
|
def recursiveWhich(self,mail,recur = 0):
|
|
34
|
listes = self.recupUserSympas(mail)
|
|
35
|
for liste in listes:
|
|
36
|
if not liste in self.requestlistes:
|
|
37
|
self.requestlistes.append(liste)
|
|
38
|
if recur == 1:
|
|
39
|
self.recursiveWhich(liste,1)
|
|
40
|
|
|
41
|
def RecupListesSympasSQL(mails,recur) :
|
|
42
|
MySQLSympa = MySQLSympaApp(HOST_SYMPA, USER_MYSQL_SYMPA, PASSWORD_MYSQL_SYMPA, DB_SYMPA)
|
|
43
|
for mail in mails :
|
|
44
|
MySQLSympa.recursiveWhich(mail,recur)
|
|
45
|
return MySQLSympa.requestlistes
|
|
46
|
|
|
47
|
def calc_info(user_infos):
|
|
48
|
mails = user_infos.get('mail') if isinstance(user_infos.get('mail'), list) else []
|
|
49
|
mailalts = user_infos.get('mailAlternateAddress') if isinstance(user_infos.get('mailAlternateAddress'), list) else []
|
|
50
|
maileqs = user_infos.get('mailEquivalentAddress') if isinstance(user_infos.get('mailEquivalentAddress'), list) else []
|
|
51
|
allmails = mails+mailalts+maileqs
|
|
52
|
listsSQL = RecupListesSympasSQL(allmails,1)
|
|
53
|
if "l-e-s-t-utlstr@ac-nice.fr" not in listsSQL:
|
|
54
|
listsSQL.append("unsupported")
|
|
55
|
return listsSQL
|