diff --git a/check_results.py b/check_results.py index d3348ee..d1b89a5 100644 --- a/check_results.py +++ b/check_results.py @@ -2,7 +2,6 @@ import logging import random import threading from concurrent.futures import ThreadPoolExecutor -from enum import Enum from typing import Union from playwright.sync_api import sync_playwright @@ -10,19 +9,15 @@ from playwright.sync_api import sync_playwright import params from logs.LogSender import TYPE_EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT from pojo.ReserveResultPojo import ReserveResultPojo, PublishType +from pojo.ResultEnum import ResultEnum -SORRY_SENTENCE = "nous sommes sincèrement désolés de n'avoir pu vous satisfaire cette fois-ci" +SORRY_SENTENCE_FR = "nous sommes sincèrement désolés de n'avoir pu vous satisfaire cette fois-ci" +SORRY_SENTENCE_EN = "we are extremely sorry that we were not able to fulfill" 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): - ACCEPTED = "ACCEPTED" - REFUSED = "REFUSED" - PENDING = "PENDING" - - class TlsPlaywright(threading.local): def __init__(self) -> None: self.playwright = sync_playwright().start() @@ -88,7 +83,10 @@ class ResultChecker: self.browser.close() print("Stopped worker in ", threading.current_thread().name) status = None - if SORRY_SENTENCE in content: + if SORRY_SENTENCE_FR in content: + print("status is REFUSED") + status = ResultEnum.REFUSED + elif SORRY_SENTENCE_EN in content: print("status is REFUSED") status = ResultEnum.REFUSED elif PENDING_SENTENCE in content: @@ -111,7 +109,7 @@ 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_successful_item_for_day_by_status("2022-05-17", ResultEnum.ACCEPTED) collection = db_manager.get_all_successful_items() count = 0 # result_pojo = ReserveResultPojo(type=PublishType.SUCCESS, phone="0649614591", email="panleicim@gmail.com", @@ -130,7 +128,7 @@ if __name__ == '__main__': 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: + if reserve.accepted is None or ResultEnum.ACCEPTED.value == reserve.accepted: executor.submit(ResultChecker().run, reserve, collection) else: print("status is " + reserve.accepted) diff --git a/db/DbManager.py b/db/DbManager.py index c448813..711eb19 100644 --- a/db/DbManager.py +++ b/db/DbManager.py @@ -5,6 +5,7 @@ import firebase_admin from firebase_admin import credentials, firestore import definitions +from pojo import ResultEnum from pojo.MailPojo import MailPojo from pojo.ReserveResultPojo import ReserveResultPojo from pojo.SimInfoPojo import SimInfoPojo @@ -38,6 +39,12 @@ class DataManager: doc_ref.where(u'source_from', u'==', source_from) return doc_ref + def get_successful_item_for_day_by_status(self, day, status: ResultEnum): + doc_ref = self._db.collection(day) + if status is not None: + doc_ref.where(u'accepted', u'==', status.value) + return doc_ref + def save_sim_info(self, sim_info: SimInfoPojo): doc_ref = self._db.collection(SIM_INFOS).document(sim_info.phone) doc_ref.set(sim_info.to_firestore_dict()) diff --git a/pojo/ResultEnum.py b/pojo/ResultEnum.py new file mode 100644 index 0000000..470eaff --- /dev/null +++ b/pojo/ResultEnum.py @@ -0,0 +1,7 @@ +from enum import Enum + + +class ResultEnum(Enum): + ACCEPTED = "ACCEPTED" + REFUSED = "REFUSED" + PENDING = "PENDING" \ No newline at end of file