Merge remote-tracking branch 'origin/feature/mailer'
This commit is contained in:
+4
-1
@@ -4,6 +4,7 @@ from playwright.sync_api import sync_playwright
|
||||
|
||||
import params
|
||||
from db.DbManager import DataManager
|
||||
from logs.LogSender import EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||
|
||||
SORRY_SENTENCE = "nous sommes sincèrement désolés de n'avoir pu vous satisfaire cette fois-ci"
|
||||
@@ -47,13 +48,15 @@ def run(playwright, url) -> ResultEnum:
|
||||
# need to start at 21h00
|
||||
if __name__ == '__main__':
|
||||
# get the list
|
||||
params.oracle_log_sender.send_log(msg="开始检查约会结果", subject=LOG_SUBJECT_EVENT, type=EVENT_CHECK_RESULTS)
|
||||
db_manager = params.firebase_store_manager
|
||||
collection = db_manager.get_all_successful_items()
|
||||
count = 0
|
||||
for appointment in collection.stream():
|
||||
count = count + 1
|
||||
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
||||
print("status is " + reserve_pojo.accepted)
|
||||
if reserve_pojo.accepted:
|
||||
print("status is " + reserve_pojo.accepted)
|
||||
if reserve_pojo.accepted is None or ResultEnum.PENDING.value == reserve_pojo.accepted:
|
||||
result = check_result_page(reserve_pojo.url)
|
||||
collection.document(reserve_pojo.id).update({u'accepted': result.name})
|
||||
|
||||
+13
-1
@@ -3,7 +3,9 @@ import firebase_admin
|
||||
import xlsxwriter as xlsxwriter
|
||||
from firebase_admin import credentials, firestore
|
||||
|
||||
import definitions
|
||||
import params
|
||||
from pojo.MailPojo import MailPojo
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
||||
from pojo.SimInfoPojo import SimInfoPojo
|
||||
from pojo.contact_pojo import ContactPojo
|
||||
@@ -11,6 +13,7 @@ from utils.excel_reader import ExcelHelper
|
||||
|
||||
ERROR_COLLECTION_NAME = "error_items"
|
||||
CONTACT_COLLECTION_NAME = "contact_list"
|
||||
MAIL_COLLECTION_NAME = "mail_list"
|
||||
SIM_INFOS = "sim_infos"
|
||||
TIMEOUT = "timeout_items"
|
||||
|
||||
@@ -19,7 +22,7 @@ class DataManager:
|
||||
batch_size = 20
|
||||
|
||||
def __init__(self):
|
||||
cred = credentials.Certificate("appointment.json")
|
||||
cred = credentials.Certificate(definitions.ROOT_DIR + "/appointment.json")
|
||||
self._app = firebase_admin.initialize_app(cred)
|
||||
self._db = firestore.client()
|
||||
contact_collection = self._db.collection(CONTACT_COLLECTION_NAME)
|
||||
@@ -119,8 +122,17 @@ class DataManager:
|
||||
contact_collection = self._db.collection(CONTACT_COLLECTION_NAME)
|
||||
return contact_collection
|
||||
|
||||
def get_mail_list(self) -> list:
|
||||
mail_collection = self._db.collection(MAIL_COLLECTION_NAME)
|
||||
mail_list = []
|
||||
for mail in mail_collection.stream():
|
||||
mail_pojo = MailPojo.from_firestore_dict(mail.to_dict())
|
||||
mail_list.append(mail_pojo)
|
||||
return mail_list
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# params.firebase_store_manager.upload_contact_list_to_cloud()
|
||||
params.firebase_store_manager.save_to_excel()
|
||||
# params.firebase_store_manager.clear_all_sim_info()
|
||||
# print(params.firebase_store_manager.get_mail_list())
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import os
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
+3
-1
@@ -1,8 +1,10 @@
|
||||
import logging
|
||||
|
||||
import definitions
|
||||
|
||||
|
||||
def init_logger():
|
||||
logging.basicConfig(filename="appointment.log",
|
||||
logging.basicConfig(filename=definitions.ROOT_DIR + "/appointment.log",
|
||||
filemode='a',
|
||||
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
|
||||
datefmt='%D:%H:%M:%S',
|
||||
|
||||
+4
-1
@@ -10,8 +10,11 @@ from logs.AppLogging import init_logger
|
||||
from pojo import ReserveResultPojo
|
||||
from pojo.ReserveResultPojo import PublishType
|
||||
|
||||
# Log type
|
||||
LOG_SUBJECT_EVENT = "EVENT"
|
||||
EVENT_CHECK_RESULTS = "EVENT_CHECK_RESULTS"
|
||||
LOG_ERROR = "ERROR"
|
||||
LOG_INFO = "INFO"
|
||||
LOG_TYPE_INFO = "INFO"
|
||||
LOG_APPOINTMENT_ERROR = "APPOINTMENT_ERROR"
|
||||
LOG_APPOINTMENT_TIMEOUT = "TIMEOUT"
|
||||
LOG_APPOINTMENT_SUCCESS = "SUCCESS"
|
||||
|
||||
@@ -7,10 +7,11 @@ from typing import Union
|
||||
|
||||
from gsmmodem import GsmModem
|
||||
|
||||
import params
|
||||
from ModemPool import ModemPool
|
||||
from card_pool import CardPool
|
||||
from commandor import Commandor
|
||||
from logs.LogSender import LOG_APPOINTMENT_TIMEOUT
|
||||
from logs.LogSender import LOG_APPOINTMENT_TIMEOUT, LOG_SUBJECT_EVENT
|
||||
from params import MODEM_POOL_PORTS, CARD_POOL_PORT, firebase_store_manager, oracle_log_sender
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||
from utils.excel_reader import ExcelHelper
|
||||
@@ -159,6 +160,7 @@ def start_listen():
|
||||
|
||||
|
||||
def read_all_the_phone_number():
|
||||
params.oracle_log_sender.send_log(msg="SIM卡自检开始", subject=LOG_SUBJECT_EVENT, type=LOG_SUBJECT_EVENT)
|
||||
slot_number = 1
|
||||
slot_sum = 30
|
||||
# card_pool.switch_to_slot(29)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
from sqlalchemy import Column, String
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class Mail(Base):
|
||||
__tablename__ = 'mailer'
|
||||
id_key = Column(String(255), primary_key=True, nullable=False)
|
||||
secret_key = Column(String(255), nullable=False)
|
||||
recipient_list = Column(String(255), nullable=False)
|
||||
|
||||
def __repr__(self):
|
||||
return "Mail id_key:% s secret_key:% s recipient_list:% s" % (self.id_key, self.secret_key, self.recipient_list)
|
||||
@@ -0,0 +1,65 @@
|
||||
import base64
|
||||
import logging
|
||||
from mako.template import Template
|
||||
|
||||
import boto3
|
||||
|
||||
import definitions
|
||||
import params
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
||||
|
||||
TEMPLATE_NAME = 'scrapy_template_email'
|
||||
AWS_CLIENT_NAME = "sesv2"
|
||||
AWS_REGION_NAME = "eu-central-1"
|
||||
UTF8 = 'utf-8'
|
||||
|
||||
|
||||
class Mailer:
|
||||
|
||||
def __init__(self):
|
||||
self.logger = logging.getLogger("Mailer")
|
||||
encoded_bytes = "4JWcU9B/BzTRXIPlBDt4EobibUU7ji1Sgx+VTsEf".encode(UTF8)
|
||||
encoded_base64_bytes = base64.b64encode(encoded_bytes)
|
||||
decoded_bytes = base64.b64decode(encoded_base64_bytes)
|
||||
secret = decoded_bytes.decode(UTF8)
|
||||
self.ses_client = boto3.client(AWS_CLIENT_NAME, region_name=AWS_REGION_NAME,
|
||||
aws_access_key_id="AKIAU67WLKZUXEHXDJB5",
|
||||
aws_secret_access_key=secret)
|
||||
|
||||
def send_email(self, result_list: list):
|
||||
# recipients = params.firebase_store_manager.get_mail_list()
|
||||
|
||||
recipients = ['panleicim@gmail.com']
|
||||
|
||||
mytemplate = Template(filename=definitions.ROOT_DIR + "/templates/appointment_results.html")
|
||||
self.logger.info("send email to " + str(recipients))
|
||||
self.ses_client.send_email(
|
||||
FromEmailAddress="noreply@lpaconsulting.fr",
|
||||
Destination={
|
||||
"ToAddresses": recipients
|
||||
},
|
||||
Content={
|
||||
'Simple': {
|
||||
'Subject': {
|
||||
'Data': '约会结果',
|
||||
'Charset': 'utf8'
|
||||
},
|
||||
'Body': {
|
||||
'Html': {
|
||||
'Data': mytemplate.render(result_list=result_list),
|
||||
'Charset': 'utf8'
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
result = ReserveResultPojo(email="panleicim@gmail.com", phone="0649614591", url="url", firstName="Lei",
|
||||
lastName="PAN", message="msg", type=PublishType.SUCCESS)
|
||||
|
||||
mytemplate = Template(filename=definitions.ROOT_DIR + "/templates/appointment_results.html")
|
||||
print(mytemplate.render(result_list=[result]))
|
||||
# mailer = Mailer()
|
||||
# mailer.send_email([result])
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
from db.DbManager import DataManager
|
||||
from logs.LogSender import LogSender
|
||||
|
||||
@@ -23,5 +24,3 @@ CARD_POOL_PORT = "/dev/tty.usbmodem1432101"
|
||||
|
||||
firebase_store_manager = DataManager()
|
||||
oracle_log_sender = LogSender()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class MailPojo:
|
||||
email: str
|
||||
|
||||
def __init__(self, email: str):
|
||||
self.email = email
|
||||
|
||||
@staticmethod
|
||||
def from_firestore_dict(source):
|
||||
email = source['email']
|
||||
result = MailPojo(email=email)
|
||||
return result
|
||||
|
||||
def __repr__(self):
|
||||
return "email = " + self.email
|
||||
@@ -31,11 +31,12 @@ class ReserveResultPojo:
|
||||
email = source['email']
|
||||
lastName = source['lastName']
|
||||
firstName = source['firstName']
|
||||
accepted = source['accepted']
|
||||
result = ReserveResultPojo(type=publish_type, phone=phone,
|
||||
message=message, url=url, email=email,
|
||||
firstName=firstName, lastName=lastName)
|
||||
result.accepted = accepted
|
||||
if 'accepted' in source:
|
||||
accepted = source['accepted']
|
||||
result.accepted = accepted
|
||||
result.id = id
|
||||
return result
|
||||
|
||||
|
||||
@@ -8,3 +8,6 @@ python_gsmmodem_new==0.13.0
|
||||
|
||||
dataclasses~=0.6
|
||||
oci~=2.54.1
|
||||
XlsxWriter~=3.0.3
|
||||
SQLAlchemy~=1.4.29
|
||||
boto3~=1.21.13
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/zsh
|
||||
/Users/panlei/Documents/worksapce/appointment_modem_pool/venv/bin/python3 /Users/panlei/Documents/worksapce/appointment_modem_pool/main.py
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
% for result in result_list:
|
||||
<li>姓名:${result.lastName} ${result.firstName}, 电话: ${result.phone}, <br/>邮件: ${result.email}</li>
|
||||
% endfor
|
||||
</ul>
|
||||
Reference in New Issue
Block a user