optimization on check_results.py

This commit is contained in:
PAN Lei
2022-05-21 17:48:52 +02:00
parent bce39de000
commit 2839dac6ef
2 changed files with 15 additions and 19 deletions
+8 -19
View File
@@ -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: