From b1d94ac92d070cbc8ebb30cfd5617f91c2fe2a3f Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Fri, 19 Aug 2022 19:35:27 +0200 Subject: [PATCH] send email when rdv confirmed --- read_confirmation_emails.py | 4 ++-- src/mail/mail_confirmation.py | 32 +++++++++++++++----------------- src/utils/excel_reader.py | 8 +++++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/read_confirmation_emails.py b/read_confirmation_emails.py index 3326ace..eff5c15 100644 --- a/read_confirmation_emails.py +++ b/read_confirmation_emails.py @@ -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__': - read_mails() \ No newline at end of file + read_mails_and_find_confirmation_contacts() \ No newline at end of file diff --git a/src/mail/mail_confirmation.py b/src/mail/mail_confirmation.py index bfe8cc9..edd0494 100644 --- a/src/mail/mail_confirmation.py +++ b/src/mail/mail_confirmation.py @@ -10,6 +10,8 @@ from builtins import list from src import params 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.proxy.proxy_type import ProxyType from src.workers.link_validator import LinkValidator @@ -45,16 +47,7 @@ class MailConfirmationReader(): mail_list = [] print("read mails from {}".format(self.login)) # 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, folder="Bulk")) # close the connection and logout imap.close() imap.logout() @@ -137,8 +130,8 @@ def need_to_valid_url(url: str, successful_items) -> bool: return False -def read_mails(): - # get email address +def read_mails_and_find_confirmation_contacts(): + mailer = Mailer() mail_list = MONGO_STORE_MANAGER.get_destination_emails() # # mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq") # # mail_address2 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb") @@ -153,13 +146,18 @@ def read_mails(): for mail in mail_list: mail_reader = MailConfirmationReader(mail.mail, mail.password) executor.submit(mail_reader.read_emails, mails_messages) - - for mail in mails_messages: - print(mail.mail_address) - print(mail.subject) - print(mail.body) + if len(mails_messages) > 0: + successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day() + 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.subject) + print(mail.body) # check whether the url has already been clicked if __name__ == '__main__': - read_mails() + read_mails_and_find_confirmation_contacts() diff --git a/src/utils/excel_reader.py b/src/utils/excel_reader.py index 7019864..e45657a 100644 --- a/src/utils/excel_reader.py +++ b/src/utils/excel_reader.py @@ -188,6 +188,7 @@ def write_destinaire_email(valid_contacts: list, generate_passport=True): row += 1 workbook.close() + def save_mails_to_db(): excel_reader = ExcelHelper() 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: MONGO_STORE_MANAGER.save_destinary_emails(mail) + if __name__ == '__main__': # 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) # write_new_contacts_to_excel(valid_contacts=contacts) save_mails_to_db() # for mail in excel_reader.read_mails_and_pwd(): # MONGO_STORE_MANAGER.insert_email(mail) - # for i in range(1,2): - # print(get_random_phone_numbers()) \ No newline at end of file + # for i in range(1, 64): + # print(get_random_phone_numbers())