correction for check_results

This commit is contained in:
2022-05-17 23:52:21 +02:00
parent 08a5cc2808
commit ad822c0b17
3 changed files with 23 additions and 11 deletions
+9 -11
View File
@@ -2,7 +2,6 @@ import logging
import random import random
import threading import threading
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from enum import Enum
from typing import Union from typing import Union
from playwright.sync_api import sync_playwright from playwright.sync_api import sync_playwright
@@ -10,19 +9,15 @@ from playwright.sync_api import sync_playwright
import params import params
from logs.LogSender import TYPE_EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT from logs.LogSender import TYPE_EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType 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" 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 = "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." 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): class TlsPlaywright(threading.local):
def __init__(self) -> None: def __init__(self) -> None:
self.playwright = sync_playwright().start() self.playwright = sync_playwright().start()
@@ -88,7 +83,10 @@ class ResultChecker:
self.browser.close() self.browser.close()
print("Stopped worker in ", threading.current_thread().name) print("Stopped worker in ", threading.current_thread().name)
status = None 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") print("status is REFUSED")
status = ResultEnum.REFUSED status = ResultEnum.REFUSED
elif PENDING_SENTENCE in content: elif PENDING_SENTENCE in content:
@@ -111,7 +109,7 @@ if __name__ == '__main__':
# get the list # get the list
params.oracle_log_sender.send_log(msg="开始检查约会结果", subject=LOG_SUBJECT_EVENT, type=TYPE_EVENT_CHECK_RESULTS) params.oracle_log_sender.send_log(msg="开始检查约会结果", subject=LOG_SUBJECT_EVENT, type=TYPE_EVENT_CHECK_RESULTS)
db_manager = params.firebase_store_manager 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() collection = db_manager.get_all_successful_items()
count = 0 count = 0
# result_pojo = ReserveResultPojo(type=PublishType.SUCCESS, phone="0649614591", email="panleicim@gmail.com", # 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: with ThreadPoolExecutor(max_workers=5) as executor:
for reserve in result_list: for reserve in result_list:
count = count + 1 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) executor.submit(ResultChecker().run, reserve, collection)
else: else:
print("status is " + reserve.accepted) print("status is " + reserve.accepted)
+7
View File
@@ -5,6 +5,7 @@ import firebase_admin
from firebase_admin import credentials, firestore from firebase_admin import credentials, firestore
import definitions import definitions
from pojo import ResultEnum
from pojo.MailPojo import MailPojo from pojo.MailPojo import MailPojo
from pojo.ReserveResultPojo import ReserveResultPojo from pojo.ReserveResultPojo import ReserveResultPojo
from pojo.SimInfoPojo import SimInfoPojo from pojo.SimInfoPojo import SimInfoPojo
@@ -38,6 +39,12 @@ class DataManager:
doc_ref.where(u'source_from', u'==', source_from) doc_ref.where(u'source_from', u'==', source_from)
return doc_ref 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): def save_sim_info(self, sim_info: SimInfoPojo):
doc_ref = self._db.collection(SIM_INFOS).document(sim_info.phone) doc_ref = self._db.collection(SIM_INFOS).document(sim_info.phone)
doc_ref.set(sim_info.to_firestore_dict()) doc_ref.set(sim_info.to_firestore_dict())
+7
View File
@@ -0,0 +1,7 @@
from enum import Enum
class ResultEnum(Enum):
ACCEPTED = "ACCEPTED"
REFUSED = "REFUSED"
PENDING = "PENDING"