From 2dcff47fb3ab2b720a41324226e3ca40b335a17d Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Mon, 16 May 2022 22:25:19 +0200 Subject: [PATCH] optimize the check_results.py --- check_results.py | 23 ++++++++++++++--------- db/DbManager.py | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/check_results.py b/check_results.py index 8d7915c..d3348ee 100644 --- a/check_results.py +++ b/check_results.py @@ -14,6 +14,7 @@ from pojo.ReserveResultPojo import ReserveResultPojo, PublishType SORRY_SENTENCE = "nous sommes sincèrement désolés de n'avoir pu vous satisfaire cette fois-ci" NOT_AVAILABLE_CONTENT = "For more than 130 years, our House has offered its full expertise to satisfy" 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." class ResultEnum(Enum): @@ -74,7 +75,7 @@ class ResultChecker: "password": params.PROXY_PASSWORD } while content is None: - content = self.load_page(self.tls.playwright, proxy, url) + content = self.load_page(self.tls.playwright, proxy, url) random_id_number = params.get_random_id_number_for_proxy() proxy_username = "panleicim-res-fr-" + random_id_number print("proxy_username is " + proxy_username) @@ -93,6 +94,9 @@ class ResultChecker: elif PENDING_SENTENCE in content: print("status is PENDING") status = ResultEnum.PENDING + elif PENDING_SENTENCE_EN in content: + print("status is PENDING") + status = ResultEnum.PENDING elif NOT_AVAILABLE_CONTENT in content: print("status is REFUSED") status = ResultEnum.REFUSED @@ -107,22 +111,23 @@ if __name__ == '__main__': # get the list params.oracle_log_sender.send_log(msg="开始检查约会结果", subject=LOG_SUBJECT_EVENT, type=TYPE_EVENT_CHECK_RESULTS) db_manager = params.firebase_store_manager - collection = db_manager.get_all_successful_items_for_day("2022-05-14", "landd") + # collection = db_manager.get_all_successful_items_for_day("2022-05-14", "landd") + collection = db_manager.get_all_successful_items() count = 0 - result_pojo = ReserveResultPojo(type=PublishType.SUCCESS, phone="0649614591", email="panleicim@gmail.com", - message="SUCCESS", firstName="Lei", lastName="PAN", url='https://api.ipify.org') + # result_pojo = ReserveResultPojo(type=PublishType.SUCCESS, phone="0649614591", email="panleicim@gmail.com", + # message="SUCCESS", firstName="Lei", lastName="PAN", url='https://api.ipify.org') result_list = [] - # for appointment in collection.stream(): - # reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict()) - # result_list.append(reserve_pojo) - result_list.append(result_pojo) + for appointment in collection.stream(): + reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict()) + result_list.append(reserve_pojo) + # result_list.append(result_pojo) # for result in result_list: # if result.accepted is None or ResultEnum.PENDING.value == result.accepted: # ResultChecker().run(result, collection) # else: # print("status is " + result.accepted) - with ThreadPoolExecutor(max_workers=1) as executor: + with ThreadPoolExecutor(max_workers=5) as executor: for reserve in result_list: count = count + 1 if reserve.accepted is None or ResultEnum.PENDING.value == reserve.accepted: diff --git a/db/DbManager.py b/db/DbManager.py index 6799b33..c448813 100644 --- a/db/DbManager.py +++ b/db/DbManager.py @@ -30,7 +30,7 @@ class DataManager: return sim_info_collection def get_all_successful_items(self): - return self.get_all_successful_items_for_day(str(datetime.date.today())) + return self.get_all_successful_items_for_day(str(datetime.date.today()), None) def get_all_successful_items_for_day(self, day, source_from: Union[str, None]): doc_ref = self._db.collection(day)