add check sms and sen email if appointment is accepted

This commit is contained in:
2022-04-20 12:56:06 +02:00
parent d848ec9194
commit 71c1ff5fea
16 changed files with 130 additions and 31 deletions
+39 -3
View File
@@ -1,13 +1,23 @@
import json
import logging
import threading
import time
from typing import Union
from gsmmodem.modem import Sms
import params
from definitions import SMS_TIMEOUT
from notification.AcceptedResultPojo import get_accepted_result_from
from notification.mailer import Mailer
from pojo.SimInfoPojo import SimInfoPojo
from pojo.serial_modem import SerialModem
from utils.excel_reader import ExcelHelper
class WaitSmsWorker:
HERMES_RDV = "HERMES RDV"
ACCEPT_SENTENCE = "We are pleased to confirm your appointment"
def __init__(self, serial_modem: SerialModem):
self.serial_modem = serial_modem
@@ -18,13 +28,12 @@ class WaitSmsWorker:
"sms received for phone:{}(ccid:{})".format(self.serial_modem.phone_number, self.serial_modem.ccid))
self.logger.info(
u'== SMS message received ==\nFrom: {0}\nTime: {1}\nMessage:\n{2}\n'.format(sms.number, sms.time, sms.text))
# extract the otp number
self.check_sms(sms, self.serial_modem.ccid)
params.oracle_log_sender.send_sms_reception_log(sms.number, sms.text, self.serial_modem.ccid)
def run(self):
t = threading.Thread(target=self.start_wait)
t.start()
# t.join()
def start_wait(self):
try:
@@ -36,7 +45,6 @@ class WaitSmsWorker:
self.serial_modem.modem.smsTextMode = False
self.logger.info('Waiting for SMS message, for phone number ' + str(self.serial_modem.phone_number))
listen_at = time.time()
# threading.current_thread().join(self.OTP_TIMEOUT)
while True:
# self.logger.info("sleep for 2s in thread({})".format(threading.currentThread().name))
time.sleep(5)
@@ -47,3 +55,31 @@ class WaitSmsWorker:
# save the contact in timeout
self.serial_modem.modem.close()
return
@staticmethod
def find_info_via_ccid(ccid) -> Union[None, SimInfoPojo]:
sim_list = ExcelHelper().read_sim_info()
found_sim_list = [contact for contact in sim_list if
contact.ccid.replace("F", "") == ccid.replace("F", "")]
if len(found_sim_list) > 0:
print(found_sim_list[0].to_firestore_dict())
return found_sim_list[0]
else:
return None
def check_sms(self, sms: Sms, ccid: str):
self.logger.info("check sms")
if sms.number == self.HERMES_RDV:
if self.ACCEPT_SENTENCE in sms.text:
self.logger.info("收到来自hermes的短信,准备发送邮件")
mailer = Mailer()
sim_info = self.find_info_via_ccid(ccid)
accepted_result = get_accepted_result_from(sms, sim_info)
mailer.send_email(accepted_result)
if __name__ == '__main__':
worker = WaitSmsWorker(None)
sms = Sms("HERMES RDV",
"We are pleased to confirm your appointment. You will be welcomed on Apr 14, 2022 in our store at 17 rue de Sèvres at 4:45 PM. The given hour may be subje")
worker.check_sms(sms, "8933130070216295758F")