optimization on check_results.py
This commit is contained in:
+8
-19
@@ -2,27 +2,22 @@ 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
|
||||
|
||||
import params
|
||||
from logs.LogSender import TYPE_EVENT_CHECK_RESULTS, LOG_SUBJECT_EVENT
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||
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()
|
||||
@@ -87,8 +82,10 @@ class ResultChecker:
|
||||
print(content)
|
||||
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:
|
||||
@@ -114,18 +111,10 @@ if __name__ == '__main__':
|
||||
# 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_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 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=5) as executor:
|
||||
for reserve in result_list:
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ResultEnum(Enum):
|
||||
ACCEPTED = "ACCEPTED"
|
||||
REFUSED = "REFUSED"
|
||||
PENDING = "PENDING"
|
||||
Reference in New Issue
Block a user