send email when rdv confirmed

This commit is contained in:
2022-08-19 19:35:27 +02:00
parent fd1af1778c
commit b1d94ac92d
3 changed files with 22 additions and 22 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
from src.mail.mail_confirmation import read_mails from src.mail.mail_confirmation import read_mails_and_find_confirmation_contacts
if __name__ == '__main__': if __name__ == '__main__':
read_mails() read_mails_and_find_confirmation_contacts()
+11 -13
View File
@@ -10,6 +10,8 @@ from builtins import list
from src import params from src import params
from src.db.mongo_manager import MONGO_STORE_MANAGER from src.db.mongo_manager import MONGO_STORE_MANAGER
from src.notification.AcceptedResultPojo import get_accepted_result_from
from src.notification.mailer import Mailer
from src.pojo.mail.mail_pojo import MailPojo, MailAddress from src.pojo.mail.mail_pojo import MailPojo, MailAddress
from src.proxy.proxy_type import ProxyType from src.proxy.proxy_type import ProxyType
from src.workers.link_validator import LinkValidator from src.workers.link_validator import LinkValidator
@@ -45,16 +47,7 @@ class MailConfirmationReader():
mail_list = [] mail_list = []
print("read mails from {}".format(self.login)) print("read mails from {}".format(self.login))
# self.show_folders(imap) # self.show_folders(imap)
# total number of emails
# get mails from inbox
# (\Archive \HasNoChildren) = "Archive"
# (\Junk \HasNoChildren) = "Bulk"
# (\Drafts \HasNoChildren) = "Draft"
# (\HasNoChildren) = "Inbox"
# (\Sent \HasNoChildren) = "Sent"
# (\Trash \HasNoChildren) = "Trash"
mail_list.extend(self._get_messages_from_folder(imap)) mail_list.extend(self._get_messages_from_folder(imap))
# mail_list.extend(self._get_messages_from_folder(imap, folder="Bulk"))
# close the connection and logout # close the connection and logout
imap.close() imap.close()
imap.logout() imap.logout()
@@ -137,8 +130,8 @@ def need_to_valid_url(url: str, successful_items) -> bool:
return False return False
def read_mails(): def read_mails_and_find_confirmation_contacts():
# get email address mailer = Mailer()
mail_list = MONGO_STORE_MANAGER.get_destination_emails() mail_list = MONGO_STORE_MANAGER.get_destination_emails()
# # mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq") # # mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq")
# # mail_address2 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb") # # mail_address2 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb")
@@ -153,8 +146,13 @@ def read_mails():
for mail in mail_list: for mail in mail_list:
mail_reader = MailConfirmationReader(mail.mail, mail.password) mail_reader = MailConfirmationReader(mail.mail, mail.password)
executor.submit(mail_reader.read_emails, mails_messages) executor.submit(mail_reader.read_emails, mails_messages)
if len(mails_messages) > 0:
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
for mail in mails_messages: for mail in mails_messages:
message_body = mail.body
for item in successful_items:
if item.id in message_body:
mailer.send_email(get_accepted_result_from(item), to_all=False)
print(mail.mail_address) print(mail.mail_address)
print(mail.subject) print(mail.subject)
print(mail.body) print(mail.body)
@@ -162,4 +160,4 @@ def read_mails():
# check whether the url has already been clicked # check whether the url has already been clicked
if __name__ == '__main__': if __name__ == '__main__':
read_mails() read_mails_and_find_confirmation_contacts()
+4 -2
View File
@@ -188,6 +188,7 @@ def write_destinaire_email(valid_contacts: list, generate_passport=True):
row += 1 row += 1
workbook.close() workbook.close()
def save_mails_to_db(): def save_mails_to_db():
excel_reader = ExcelHelper() excel_reader = ExcelHelper()
emails = excel_reader.read_email_pojo("/Users/lpan/Downloads/aol_mails_21.xlsx") emails = excel_reader.read_email_pojo("/Users/lpan/Downloads/aol_mails_21.xlsx")
@@ -195,14 +196,15 @@ def save_mails_to_db():
for mail in emails: for mail in emails:
MONGO_STORE_MANAGER.save_destinary_emails(mail) MONGO_STORE_MANAGER.save_destinary_emails(mail)
if __name__ == '__main__': if __name__ == '__main__':
# excel_reader = ExcelHelper() # excel_reader = ExcelHelper()
# contacts = excel_reader.read_names("/Users/lpan/Documents/rdv/real_contacts_318.xlsx") # contacts = excel_reader.read_names("/Users/lpan/Documents/rdv/backup_500.xlsx")
# print(contacts) # print(contacts)
# write_new_contacts_to_excel(valid_contacts=contacts) # write_new_contacts_to_excel(valid_contacts=contacts)
save_mails_to_db() save_mails_to_db()
# for mail in excel_reader.read_mails_and_pwd(): # for mail in excel_reader.read_mails_and_pwd():
# MONGO_STORE_MANAGER.insert_email(mail) # MONGO_STORE_MANAGER.insert_email(mail)
# for i in range(1,2): # for i in range(1, 64):
# print(get_random_phone_numbers()) # print(get_random_phone_numbers())