From cf7155f9fbf02cf85cec18ef7ebd8a2a2f73f3e3 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 25 Oct 2023 18:35:27 +0200 Subject: [PATCH] send confirmation info by signal --- read_confirmation_emails.py | 0 src/mail/mail_address_validator.py | 13 ++++-------- src/mail/mail_confirmation.py | 13 ++++++++---- src/notification/SignalSender.py | 32 ++++++++++++++++++++++++++++++ src/templates/signal_results.html | 12 +++++++++++ 5 files changed, 57 insertions(+), 13 deletions(-) mode change 100644 => 100755 read_confirmation_emails.py mode change 100644 => 100755 src/mail/mail_address_validator.py mode change 100644 => 100755 src/mail/mail_confirmation.py create mode 100644 src/notification/SignalSender.py create mode 100755 src/templates/signal_results.html diff --git a/read_confirmation_emails.py b/read_confirmation_emails.py old mode 100644 new mode 100755 diff --git a/src/mail/mail_address_validator.py b/src/mail/mail_address_validator.py old mode 100644 new mode 100755 index 2da626d..0b274ec --- a/src/mail/mail_address_validator.py +++ b/src/mail/mail_address_validator.py @@ -13,12 +13,6 @@ class MailAddressValidator(): self.login = login self.password = password - @staticmethod - def show_folders(imap): - for i in imap.list()[1]: - l = i.decode().split(' "/" ') - print(l[0] + " = " + l[1]) - def is_valid_email_address(self) -> bool: # authenticate imap = create_imap(self.login) @@ -66,9 +60,10 @@ def find_and_update_invalid_emails(mail_list): if __name__ == '__main__': - # remove_invalid_email() - mail_list = MONGO_STORE_MANAGER.get_destination_emails() + remove_invalid_email() + + # mail_list = MONGO_STORE_MANAGER.get_destination_emails() # excel_reader = ExcelHelper() # mail_list = excel_reader.read_mails_and_pwd(file_name="/Users/lpan/Downloads/hotmail_list.xlsx") # print(email_list) - find_and_update_invalid_emails(mail_list) + # find_and_update_invalid_emails(mail_list) diff --git a/src/mail/mail_confirmation.py b/src/mail/mail_confirmation.py old mode 100644 new mode 100755 index 20971ba..43c69ea --- a/src/mail/mail_confirmation.py +++ b/src/mail/mail_confirmation.py @@ -11,13 +11,14 @@ from src.db.mirgration.migration_tools import migre_accepted_appointment from src.db.mongo_manager import MONGO_STORE_MANAGER from src.mail.mail_constants import create_imap, show_folders from src.notification.AcceptedResultPojo import get_accepted_result_from +from src.notification.SignalSender import SignalSender from src.notification.mailer import Mailer from src.pojo.ResultEnum import ResultEnum -from src.pojo.mail.mail_pojo import MailPojo +from src.pojo.mail.mail_pojo import MailPojo, MailAddress from src.utils.excel_reader import ExcelHelper -CONFIRMATION_SUBJECT_FR = 'Votre rendez-vous est' -CONFIRMATION_SUBJECT_EN = 'appointment is confirmed' +CONFIRMATION_SUBJECT_FR = 'rendez-vous est' +CONFIRMATION_SUBJECT_EN = 'confirmed' HERMES_EMAIL = "no-reply@hermes.com" date_format = "%d-%b-%Y" # DD-Mon-YYYY e.g., 3-Mar-2014 @@ -145,10 +146,13 @@ def clean(text): def accept_appointment_found(accepted_result_list: list): mailer = Mailer() + sginal = SignalSender() print(accepted_result_list) for reserve in accepted_result_list: - mailer.send_email(get_accepted_result_from(reserve, MONGO_STORE_MANAGER), to_all=True) + result = get_accepted_result_from(reserve, MONGO_STORE_MANAGER) + mailer.send_email(result, to_all=False) MONGO_STORE_MANAGER.update_reserve_result(reserve.id, ResultEnum.ACCEPTED, reserve.message) + sginal.send_result(result) if len(accepted_result_list) > 0: migre_accepted_appointment(str(datetime.date.today())) @@ -156,6 +160,7 @@ def accept_appointment_found(accepted_result_list: list): def read_mails_and_find_confirmation_contacts(): mail_list = MONGO_STORE_MANAGER.get_destination_emails() + mail_list.reverse() # excel_reader = ExcelHelper() # mail_list =excel_reader.read_email_pojo(file_name="/Users/lpan/Desktop/hotmail_list.xlsx") # mail_address3 = MailAddress(mail="taibenchragu1978@onet.pl", password="2J)kyfNgyOZ") diff --git a/src/notification/SignalSender.py b/src/notification/SignalSender.py new file mode 100644 index 0000000..577cb43 --- /dev/null +++ b/src/notification/SignalSender.py @@ -0,0 +1,32 @@ +import requests +from mako.template import Template + +from src import config +from src.notification.AcceptedResultPojo import AcceptedResultPojo + + +class SignalSender: + + def __init__(self): + self.group = "group.NjVhb1NrZU43TytWcTV6YUZkQVZjMmhGYUorK0pWUWJOaGhvS1JUMVYwbz0=" + + def send_message(self, msg): + x = requests.post("http://appointment.lpaconsulting.fr:10086/v2/send", json= + {"message": msg, "number": "+33768562195", + "recipients": ["group.NjVhb1NrZU43TytWcTV6YUZkQVZjMmhGYUorK0pWUWJOaGhvS1JUMVYwbz0="]} + ) + print(x.text) + + def send_result(self, result: AcceptedResultPojo): + mytemplate = Template(filename=config.ROOT_DIR + "/templates/signal_results.html") + msg = mytemplate.render(result=result) + self.send_message(msg=msg) + + +if __name__ == '__main__': + acceptedResultPojo = AcceptedResultPojo(msg="测序
测试", + url="https://rendezvousparis.hermes.com/client/register/AQ57C9", + slot_position="", sim_position="", passport="test", email="test@test.com", + name="test test", phone="0649614591", ccid="", created_at="", + validated_at="") + SignalSender().send_result(acceptedResultPojo) diff --git a/src/templates/signal_results.html b/src/templates/signal_results.html new file mode 100755 index 0000000..bda735d --- /dev/null +++ b/src/templates/signal_results.html @@ -0,0 +1,12 @@ +姓名:${result.name} + +电话: ${result.phone} + +邮件: ${result.email}, 密码: ${result.mail_password} (用网易邮箱大师登录) + +护照: ${result.passport} + +约会 url: ${result.url} + +邮件内容: ${result.message} +