310 lines
11 KiB
Python
310 lines
11 KiB
Python
|
|
import pymongo
|
|
from pymongo import MongoClient
|
|
import json
|
|
from bson import ObjectId
|
|
import re
|
|
from datetime import datetime
|
|
import prj_common as mycommon
|
|
import secrets
|
|
import inspect
|
|
import sys, os
|
|
import csv
|
|
import pandas as pd
|
|
from pymongo import ReturnDocument
|
|
from math import isnan
|
|
import GlobalVariable as MYSY_GV
|
|
import ela_index_bdd_classes as eibdd
|
|
import email_mgt as email
|
|
|
|
from validate_email import validate_email
|
|
def email_validation():
|
|
try:
|
|
|
|
coll_emails = MYSY_GV.dbname['bdd_email']
|
|
|
|
cpt = 0
|
|
nb_doc = coll_emails.count_documents({'valide':'1', "checked": {"$ne": "1"}})
|
|
|
|
print(" ### nb_doc = ", nb_doc)
|
|
|
|
|
|
for val in coll_emails.find({'valide':'1', "checked": {"$ne": "1"}}):
|
|
cpt = cpt + 1
|
|
if ("email_address" in val.keys()):
|
|
|
|
is_valid = validate_email(
|
|
email_address=val['email_address'],
|
|
check_format=True,
|
|
check_blacklist=True,
|
|
check_dns=True,
|
|
dns_timeout=10,
|
|
check_smtp=True,
|
|
smtp_timeout=10,
|
|
smtp_helo_host='smtp.office365.com',
|
|
smtp_from_address='support@mysy-training.com',
|
|
smtp_skip_tls=False,
|
|
smtp_tls_context=None,
|
|
smtp_debug=False)
|
|
|
|
retval = ""
|
|
checked_status = ""
|
|
if( is_valid ):
|
|
#print(" ### l'adresse ",val['email_address']," est valide ")
|
|
retval = True
|
|
checked_status = "1"
|
|
else:
|
|
#print(" ### l'adresse ", val['email_address'], " N'EST PAS valide ")
|
|
retval = False
|
|
checked_status = "0"
|
|
|
|
mydata = {}
|
|
mytoday = datetime.today().strftime("%d/%m/%Y")
|
|
mydata['last_check_date'] = str(mytoday)[0:10]
|
|
|
|
mydata['checked'] = str("1")
|
|
mydata['checked_status'] = str(checked_status)
|
|
|
|
ret_val = coll_emails.find_one_and_update(
|
|
{'email_address': str(val['email_address']), 'valide': '1'},
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
print(" ### "+str(cpt)+" email traité sur "+str(nb_doc))
|
|
|
|
|
|
return retval, str(cpt)+" adresse email ont été mise à jour "
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer la formation"
|
|
|
|
|
|
def email_validation_mairies():
|
|
try:
|
|
|
|
coll_emails = MYSY_GV.dbname['collect_list_mairies']
|
|
|
|
cpt = 0
|
|
nb_doc = coll_emails.count_documents({'valide': '1', "email_checked": {"$ne": "1"}})
|
|
|
|
print(" ### nb_doc = ", nb_doc)
|
|
|
|
for val in coll_emails.find({'valide': '1', "checked": {"$ne": "1"}}):
|
|
cpt = cpt + 1
|
|
if ("email" in val.keys()):
|
|
|
|
is_valid = validate_email(
|
|
email_address=str(val['email']).strip(),
|
|
check_format=True,
|
|
check_blacklist=True,
|
|
check_dns=True,
|
|
dns_timeout=10,
|
|
check_smtp=True,
|
|
smtp_timeout=10,
|
|
smtp_helo_host='smtp.office365.com',
|
|
smtp_from_address='support@mysy-training.com',
|
|
smtp_skip_tls=False,
|
|
smtp_tls_context=None,
|
|
smtp_debug=False)
|
|
|
|
retval = ""
|
|
checked_status = ""
|
|
if (is_valid):
|
|
# print(" ### l'adresse ",val['email_address']," est valide ")
|
|
retval = True
|
|
checked_status = "1"
|
|
else:
|
|
# print(" ### l'adresse ", val['email_address'], " N'EST PAS valide ")
|
|
retval = False
|
|
checked_status = "0"
|
|
|
|
mydata = {}
|
|
mytoday = datetime.today().strftime("%d/%m/%Y")
|
|
mydata['last_check_date'] = str(mytoday)[0:10]
|
|
|
|
mydata['email_checked'] = str("1")
|
|
mydata['email_checked_status'] = str(checked_status)
|
|
|
|
ret_val = coll_emails.find_one_and_update(
|
|
{'email': str(val['email']), 'valide': '1'},
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
print(" ### " + str(cpt) + " / " + str(nb_doc))
|
|
|
|
return retval, str(cpt) + " adresse email ont été mise à jour "
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer la formation"
|
|
|
|
|
|
def email_validation_hopitaux_ehpad():
|
|
try:
|
|
|
|
coll_emails = MYSY_GV.dbname['collect_list_hopitaux_ehpad']
|
|
|
|
cpt = 0
|
|
nb_doc = coll_emails.count_documents({'valide': '1', "email_checked": {"$ne": "1"}})
|
|
|
|
print(" ### nb_doc = ", nb_doc)
|
|
|
|
for val in coll_emails.find({'valide': '1', "checked": {"$ne": "1"}}):
|
|
cpt = cpt + 1
|
|
if ("email" in val.keys()):
|
|
|
|
is_valid = validate_email(
|
|
email_address=str(val['email']).strip(),
|
|
check_format=True,
|
|
check_blacklist=True,
|
|
check_dns=True,
|
|
dns_timeout=10,
|
|
check_smtp=True,
|
|
smtp_timeout=10,
|
|
smtp_helo_host='smtp.office365.com',
|
|
smtp_from_address='support@mysy-training.com',
|
|
smtp_skip_tls=False,
|
|
smtp_tls_context=None,
|
|
smtp_debug=False)
|
|
|
|
retval = ""
|
|
checked_status = ""
|
|
if (is_valid):
|
|
# print(" ### l'adresse ",val['email_address']," est valide ")
|
|
retval = True
|
|
checked_status = "1"
|
|
else:
|
|
# print(" ### l'adresse ", val['email_address'], " N'EST PAS valide ")
|
|
retval = False
|
|
checked_status = "0"
|
|
|
|
mydata = {}
|
|
mytoday = datetime.today().strftime("%d/%m/%Y")
|
|
mydata['last_check_date'] = str(mytoday)[0:10]
|
|
|
|
mydata['email_checked'] = str("1")
|
|
mydata['email_checked_status'] = str(checked_status)
|
|
|
|
ret_val = coll_emails.find_one_and_update(
|
|
{'email': str(val['email']), 'valide': '1'},
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
print(" ### " + str(cpt) + " / " + str(nb_doc))
|
|
|
|
return retval, str(cpt) + " adresse email ont été mise à jour "
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer la formation"
|
|
|
|
def email_validation_list_pos_bio():
|
|
try:
|
|
|
|
coll_emails = MYSY_GV.dbname['collect_list_pos_bio']
|
|
|
|
cpt = 0
|
|
nb_doc = coll_emails.count_documents({'valide': '1', "email_checked": {"$ne": "1"}})
|
|
|
|
print(" ### nb_doc = ", nb_doc)
|
|
|
|
for val in coll_emails.find({'valide': '1', "checked": {"$ne": "1"}}):
|
|
cpt = cpt + 1
|
|
if ("email" in val.keys()):
|
|
|
|
is_valid = validate_email(
|
|
email_address=str(val['email']).strip(),
|
|
check_format=True,
|
|
check_blacklist=True,
|
|
check_dns=True,
|
|
dns_timeout=10,
|
|
check_smtp=True,
|
|
smtp_timeout=10,
|
|
smtp_helo_host='smtp.office365.com',
|
|
smtp_from_address='support@mysy-training.com',
|
|
smtp_skip_tls=False,
|
|
smtp_tls_context=None,
|
|
smtp_debug=False)
|
|
|
|
retval = ""
|
|
checked_status = ""
|
|
if (is_valid):
|
|
# print(" ### l'adresse ",val['email_address']," est valide ")
|
|
retval = True
|
|
checked_status = "1"
|
|
else:
|
|
# print(" ### l'adresse ", val['email_address'], " N'EST PAS valide ")
|
|
retval = False
|
|
checked_status = "0"
|
|
|
|
mydata = {}
|
|
mytoday = datetime.today().strftime("%d/%m/%Y")
|
|
mydata['last_check_date'] = str(mytoday)[0:10]
|
|
|
|
mydata['email_checked'] = str("1")
|
|
mydata['email_checked_status'] = str(checked_status)
|
|
|
|
ret_val = coll_emails.find_one_and_update(
|
|
{'email': str(val['email']), 'valide': '1'},
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
print(" ### " + str(cpt) + " / " + str(nb_doc))
|
|
|
|
return retval, str(cpt) + " adresse email ont été mise à jour "
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer la formation"
|
|
|
|
def test_tab_mail(tab_mail):
|
|
try:
|
|
|
|
list_mail = ""
|
|
if ("list_mail" in tab_mail.keys()):
|
|
list_mail = str(tab_mail['list_mail'])
|
|
|
|
|
|
cpt = 0
|
|
|
|
val = list_mail
|
|
print(" list_mail = ", list_mail)
|
|
is_valid = validate_email(
|
|
email_address=str(val),
|
|
check_format=True,
|
|
check_blacklist=True,
|
|
check_dns=True,
|
|
dns_timeout=100,
|
|
check_smtp=True,
|
|
smtp_timeout=100,
|
|
smtp_helo_host='smtp.office365.com',
|
|
smtp_from_address='support@mysy-training.com',
|
|
smtp_skip_tls=False,
|
|
smtp_tls_context=None,
|
|
smtp_debug=False)
|
|
|
|
retval = ""
|
|
checked_status = ""
|
|
if (is_valid):
|
|
print(" ### l'adresse ",val," est valide ")
|
|
retval = True
|
|
else:
|
|
print(" ### l'adresse ", val, " N'EST PAS valide ")
|
|
retval = False
|
|
|
|
|
|
|
|
return retval, str(cpt) + " adresse email ont été mise à jour "
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de tester le mail" |