try to send email after check_results
This commit is contained in:
+10
-1
@@ -8,6 +8,8 @@ from playwright.sync_api import sync_playwright
|
|||||||
|
|
||||||
import params
|
import params
|
||||||
from logs.LogSender import TYPE_EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT
|
from logs.LogSender import TYPE_EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT
|
||||||
|
from notification.AcceptedResultPojo import get_accepted_result_from
|
||||||
|
from notification.mailer import Mailer
|
||||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||||
from pojo.ResultEnum import ResultEnum
|
from pojo.ResultEnum import ResultEnum
|
||||||
|
|
||||||
@@ -17,6 +19,8 @@ NOT_AVAILABLE_CONTENT = "For more than 130 years, our House has offered its full
|
|||||||
PENDING_SENTENCE = "Ce soir, entre 20:00 et 20:30, vous obtiendrez une réponse par e-mail."
|
PENDING_SENTENCE = "Ce soir, entre 20:00 et 20:30, vous obtiendrez une réponse par e-mail."
|
||||||
PENDING_SENTENCE_EN = "This evening between 20:00 and 20:30 you will receive a response by email."
|
PENDING_SENTENCE_EN = "This evening between 20:00 and 20:30 you will receive a response by email."
|
||||||
|
|
||||||
|
mailer = Mailer()
|
||||||
|
|
||||||
|
|
||||||
class TlsPlaywright(threading.local):
|
class TlsPlaywright(threading.local):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@@ -100,6 +104,11 @@ class ResultChecker:
|
|||||||
else:
|
else:
|
||||||
print("status is ACCEPTED")
|
print("status is ACCEPTED")
|
||||||
status = ResultEnum.ACCEPTED
|
status = ResultEnum.ACCEPTED
|
||||||
|
# send email
|
||||||
|
try:
|
||||||
|
mailer.send_email(get_accepted_result_from(reserve_pojo))
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
collection.document(reserve_pojo.id).update({u'accepted': status.name})
|
collection.document(reserve_pojo.id).update({u'accepted': status.name})
|
||||||
|
|
||||||
|
|
||||||
@@ -116,7 +125,7 @@ if __name__ == '__main__':
|
|||||||
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
||||||
result_list.append(reserve_pojo)
|
result_list.append(reserve_pojo)
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
with ThreadPoolExecutor(max_workers=10) as executor:
|
||||||
for reserve in result_list:
|
for reserve in result_list:
|
||||||
count = count + 1
|
count = count + 1
|
||||||
if reserve.accepted is None or ResultEnum.ACCEPTED.value == reserve.accepted:
|
if reserve.accepted is None or ResultEnum.ACCEPTED.value == reserve.accepted:
|
||||||
|
|||||||
@@ -21,15 +21,15 @@ class AcceptedResultPojo:
|
|||||||
self.url = url
|
self.url = url
|
||||||
|
|
||||||
|
|
||||||
def get_accepted_result_from(sms, sim_info: ReserveResultPojo) -> AcceptedResultPojo:
|
def get_accepted_result_from(sim_info: ReserveResultPojo) -> AcceptedResultPojo:
|
||||||
if sim_info is None:
|
if sim_info is None:
|
||||||
# send email even there are no reserve info
|
# send email even there are no reserve info
|
||||||
return AcceptedResultPojo(sms.text, slot_position=0, sim_position=0,
|
return AcceptedResultPojo("", slot_position=0, sim_position=0,
|
||||||
passport="", email="", phone="",
|
passport="", email="", phone="",
|
||||||
name="", ccid="",
|
name="", ccid="",
|
||||||
url="")
|
url="")
|
||||||
else:
|
else:
|
||||||
return AcceptedResultPojo(sms.text, slot_position=sim_info.slot_position, sim_position=sim_info.sim_position,
|
return AcceptedResultPojo("", slot_position=sim_info.slot_position, sim_position=sim_info.sim_position,
|
||||||
passport=sim_info.passport, email=sim_info.email, phone=sim_info.phone,
|
passport=sim_info.passport, email=sim_info.email, phone=sim_info.phone,
|
||||||
name="{} {}".format(sim_info.lastName, sim_info.firstName), ccid=sim_info.ccid,
|
name="{} {}".format(sim_info.lastName, sim_info.firstName), ccid=sim_info.ccid,
|
||||||
url=sim_info.url)
|
url=sim_info.url)
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ class Mailer:
|
|||||||
aws_secret_access_key=secret)
|
aws_secret_access_key=secret)
|
||||||
|
|
||||||
def send_email(self, result: AcceptedResultPojo):
|
def send_email(self, result: AcceptedResultPojo):
|
||||||
recipients = ['panleicim@gmail.com', 'kamenonly@gmail.com', 'tangliang0411@gmail.com']
|
# recipients = ['panleicim@gmail.com', 'kamenonly@gmail.com', 'tangliang0411@gmail.com']
|
||||||
# recipients = ['panleicim@gmail.com']
|
recipients = ['panleicim@gmail.com']
|
||||||
|
|
||||||
mytemplate = Template(filename=definitions.ROOT_DIR + "/templates/appointment_results.html")
|
mytemplate = Template(filename=definitions.ROOT_DIR + "/templates/appointment_results.html")
|
||||||
self.logger.info("send email to " + str(recipients))
|
self.logger.info("send email to " + str(recipients))
|
||||||
|
|||||||
Reference in New Issue
Block a user