From 5ac4f6a0fb2ba735ed9900b7cf278425549959ea Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Mon, 16 May 2022 07:01:33 +0200 Subject: [PATCH] can check results in one thread --- check_results.py | 40 +++++++++++++++++++++++++--------------- config.ini | 4 ++-- db/DbManager.py | 2 +- main.py | 2 +- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/check_results.py b/check_results.py index 7c39ebd..ca698e1 100644 --- a/check_results.py +++ b/check_results.py @@ -13,6 +13,7 @@ from logs.LogSender import TYPE_EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT 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." @@ -74,7 +75,7 @@ class ResultChecker: "password": params.PROXY_PASSWORD } while content is None: - content = self.load_page(self.tls.playwright, url, proxy) + content = self.load_page(self.tls.playwright, proxy, url) random_id_number = 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 NOT_AVAILABLE_CONTENT in content: + print("status is REFUSED") + status = ResultEnum.REFUSED else: print("status is ACCEPTED") status = ResultEnum.ACCEPTED @@ -104,20 +108,26 @@ 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() + collection = db_manager.get_all_successful_items_for_day("2022-05-14", "landd") 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(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.ACCEPTED.value == result.accepted: + ResultChecker().run(result, collection) + else: + print("status is " + result.accepted) - with ThreadPoolExecutor(max_workers=2) as executor: - for reserve in result_list: - count = count + 1 - if reserve.accepted: - print("status is " + reserve.accepted) - if reserve.accepted is None or ResultEnum.PENDING.value == reserve.accepted: - executor.submit(ResultChecker().run, reserve, collection) - print(count) + # with ThreadPoolExecutor(max_workers=1) as executor: + # for reserve in result_list: + # count = count + 1 + # if reserve.accepted: + # print("status is " + reserve.accepted) + # if reserve.accepted is None or ResultEnum.PENDING.value == reserve.accepted: + # executor.submit(ResultChecker().run, reserve, collection) + # print(count) diff --git a/config.ini b/config.ini index 4d8ff0b..151338a 100644 --- a/config.ini +++ b/config.ini @@ -1,4 +1,4 @@ [DEFAULT] -contact_list_file = /Users/panlei/IdeaProjects/appointment_tool/contact_all.xlsx -firebase_config_file = /Users/panlei/IdeaProjects/appointment_tool/appointment.json +contact_list_file = ./contact_all.xlsx +firebase_config_file = ./appointment.json LOGS_DIR = ./ \ No newline at end of file diff --git a/db/DbManager.py b/db/DbManager.py index ff7ae1a..6799b33 100644 --- a/db/DbManager.py +++ b/db/DbManager.py @@ -35,7 +35,7 @@ class DataManager: def get_all_successful_items_for_day(self, day, source_from: Union[str, None]): doc_ref = self._db.collection(day) if source_from is not None: - doc_ref.where() + doc_ref.where(u'source_from', u'==', source_from) return doc_ref def save_sim_info(self, sim_info: SimInfoPojo): diff --git a/main.py b/main.py index 120cc1e..45a2d81 100644 --- a/main.py +++ b/main.py @@ -42,4 +42,4 @@ def get_proxy(phone_number): if __name__ == '__main__': # 修改联系人行,结束联系人行 第三个参数store等于0的时候是随机,传入1的时候是总店 - start_book(1, 1, store_choose_state=0) + start_book(16, 16, store_choose_state=0)