From 12d95355f832db4dc4f837c8e499a69620a94c6d Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Mon, 16 May 2022 17:07:27 +0200 Subject: [PATCH] log double data error and too many requests error --- logs/LogSender.py | 11 +++++++++++ utils/excel_reader.py | 21 +++++++++++---------- workers/commandor_page.py | 24 +++++++++++++++++++++--- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/logs/LogSender.py b/logs/LogSender.py index efad0cf..477cf38 100644 --- a/logs/LogSender.py +++ b/logs/LogSender.py @@ -23,6 +23,9 @@ TYPE_EVENT_CHANGE_SLOT = "EVENT_CHANGE_SLOT" TYPE_SMS_RECEIVED = "TYPE_SMS_RECEIVED" LOG_ERROR = "ERROR" LOG_TYPE_INFO = "INFO" +LOG_ERROR_TYPE_DOUBLE_DATA = "DOUBLE_REQUEST_FOR_SAME_DATA" +LOG_ERROR_TOO_MANY_REQUEST_TODAY = "TOO_MANY_REQUEST_TODAY" +LOG_SUBJECT_ERROR = "ERROR" LOG_APPOINTMENT_ERROR = "APPOINTMENT_ERROR" LOG_APPOINTMENT_TIMEOUT = "TIMEOUT" LOG_APPOINTMENT_CONTACT_NOT_FOUND = "CONTACT_NOT_FOUND" @@ -67,6 +70,14 @@ class LogSender: self._identity = oci.identity.IdentityClient(self._config) self._loggingingestion_client = LoggingClient(self._config, timeout=60.0, retry_strategy=custom_retry_strategy) + def send_double_data_error(self, contact: ContactPojo): + error_msg = contact.mail + self.send_log(msg=error_msg, type=LOG_ERROR_TYPE_DOUBLE_DATA, subject=LOG_SUBJECT_ERROR) + + def send_too_many_error(self, contact: ContactPojo): + error_msg = contact.mail + self.send_log(msg=error_msg, type=LOG_ERROR_TOO_MANY_REQUEST_TODAY, subject=LOG_SUBJECT_ERROR) + def send_appoint_result(self, result: ReserveResultPojo): if result.type == PublishType.SUCCESS: # get id diff --git a/utils/excel_reader.py b/utils/excel_reader.py index fc7d133..ca72027 100644 --- a/utils/excel_reader.py +++ b/utils/excel_reader.py @@ -20,14 +20,15 @@ class ExcelHelper: contact_dict_list = json.loads(contact_list_in_json) contact_list = [] for contact_dict in contact_dict_list: - raw_name = contact_dict['name'].strip() - name = raw_name.split(' ') - last_name = name[0] - first_name = name[-1] - contact = ContactPojo(phone_number=contact_dict['phone'], - last_name=last_name, - first_name=first_name, - passport_number=contact_dict['passport'], - mail=contact_dict['email']) - contact_list.append(contact) + if contact_dict['name']: + raw_name = contact_dict['name'].strip() + name = raw_name.split(' ') + last_name = name[0] + first_name = name[-1] + contact = ContactPojo(phone_number=contact_dict['phone'], + last_name=last_name, + first_name=first_name, + passport_number=contact_dict['passport'], + mail=contact_dict['email']) + contact_list.append(contact) return contact_list diff --git a/workers/commandor_page.py b/workers/commandor_page.py index ad66bc4..1454e4a 100644 --- a/workers/commandor_page.py +++ b/workers/commandor_page.py @@ -22,6 +22,8 @@ OTP_FIELD_ID = "#sms_code" MESSAGE_FIELD_CLASS = ".message" CONFIRMED_MESSAGE = "Your request for a Leather Goods appointment has been registered" +DOUBLE_REQUEST_ERROR_MESSAGE = "A request with the same data has already been validated today." +TOO_MANY_REQUEST_ERROR_MESSAGE = "Due to a large number of requests" TIME_OUT = 400000 OTP_TIMEOUT = 240 @@ -152,7 +154,7 @@ class CommandorPage: if CONFIRMED_MESSAGE in message: # publish the successful message self.publish_message_to_queue(self.contact, PublishType.SUCCESS, self.page.url) - self.getErrors() + self.get_errors() def on_document_loaded(self): print("on_document_loaded called") @@ -191,16 +193,32 @@ class CommandorPage: except Exception as error: self.logger.error(error) - def getErrors(self): + def get_errors(self): # send error result self.publish_message_to_queue(self.contact, PublishType.ERROR, self.page.url) try: items = self.page.query_selector("div.alert") if items: - print(items.inner_html()) + erro_content = items.inner_html() + print("错误:" + erro_content) + self._handle_errors(erro_content) except Exception as ext: self.logger.error(ext) + def _handle_errors(self, erro_content: str): + if DOUBLE_REQUEST_ERROR_MESSAGE in erro_content: + # this email has been already used + params.oracle_log_sender.send_double_data_error(self.contact) + # close browser + time.sleep(2) + self.browser.close() + elif TOO_MANY_REQUEST_ERROR_MESSAGE in erro_content: + # this email has been already used + params.oracle_log_sender.send_too_many_error(self.contact) + # close browser + time.sleep(2) + self.browser.close() + def _set_email(self, email): time.sleep(get_random_wait_time()) try: