use mongodb to retreive all the reserve objects

This commit is contained in:
PAN Lei
2022-07-04 15:20:29 +02:00
parent f7ece2d169
commit 26d5649405
2 changed files with 48 additions and 19 deletions
+30 -18
View File
@@ -19,10 +19,13 @@ 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."
# URLs to ignore during checking results
BLANK_URL = "about:blank" BLANK_URL = "about:blank"
WELCOME_URL = "https://rendezvousparis.hermes.com/client/welcome"
mailer = Mailer() mailer = Mailer()
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()
@@ -58,11 +61,9 @@ class ResultChecker:
print(error) print(error)
return None return None
def run(self, reserve_pojo: ReserveResultPojo, collection): def run(self, reserve_pojo: ReserveResultPojo, firestore_collection, need_send_email=False):
print("Launched worker in ", threading.current_thread().name) print("Launched worker in ", threading.current_thread().name)
url = reserve_pojo.url url = reserve_pojo.url
# url_to_check = url.replace("register/", "")
# url_to_check = url + "?lang=fr"
print("url is " + url) print("url is " + url)
content = None content = None
proxy = params.get_proxy(ProxyType.NETNUT) proxy = params.get_proxy(ProxyType.NETNUT)
@@ -90,32 +91,43 @@ class ResultChecker:
else: else:
print("status is ACCEPTED") print("status is ACCEPTED")
status = ResultEnum.ACCEPTED status = ResultEnum.ACCEPTED
# send email if need_send_email:
try: # send email
mailer.send_email(get_accepted_result_from(reserve_pojo)) try:
except Exception as err: mailer.send_email(get_accepted_result_from(reserve_pojo))
print(err) except Exception as err:
collection.document(reserve_pojo.id).update({u'accepted': status.name}) print(err)
firestore_collection.document(reserve_pojo.id).update({u'accepted': status.name})
def check_results(): def check_results():
# 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_successful_item_for_day_by_status("2022-05-17", ResultEnum.ACCEPTED) firestore_collection = db_manager.get_all_successful_items()
collection = db_manager.get_all_successful_items() reserve_list = params.mongo_store_manager.get_all_successful_items_for_day()
count = 0 print("size is " + str(len(reserve_list)))
result_list = [] for result in reserve_list:
for appointment in collection.stream(): print(result)
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict()) # result_list = []
result_list.append(reserve_pojo) # for appointment in collection.stream():
# reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
# result_list.append(reserve_pojo)
start_check(reserve_list, firestore_collection, False)
start_check(reserve_list, firestore_collection, True)
def start_check(reserve_list, firestore_collection, need_send_email: bool):
count = 0
with ThreadPoolExecutor(max_workers=15) as executor: with ThreadPoolExecutor(max_workers=15) as executor:
for reserve in result_list: for reserve in reserve_list:
count = count + 1 count = count + 1
if reserve.accepted is None or ResultEnum.ACCEPTED.value == reserve.accepted: if reserve.accepted is None or ResultEnum.ACCEPTED.value == reserve.accepted:
if reserve.url != BLANK_URL: if reserve.url != BLANK_URL:
executor.submit(ResultChecker().run, reserve, collection) if reserve.url != WELCOME_URL:
executor.submit(ResultChecker().run, reserve, firestore_collection,
need_send_email)
else: else:
print("status is " + reserve.accepted) print("status is " + reserve.accepted)
+18 -1
View File
@@ -2,7 +2,10 @@ import datetime
import logging import logging
from pymongo import MongoClient from pymongo import MongoClient
import params
from pojo.ReserveResultPojo import ReserveResultPojo from pojo.ReserveResultPojo import ReserveResultPojo
from pojo.ResultEnum import ResultEnum
from pojo.contact_pojo import ContactPojo from pojo.contact_pojo import ContactPojo
MONGO_DB_URL = "mongo.lpaconsulting.fr" MONGO_DB_URL = "mongo.lpaconsulting.fr"
@@ -37,6 +40,20 @@ class MongoDbManager:
except Exception as error: except Exception as error:
self.logger.info(error) self.logger.info(error)
def get_all_successful_items_for_day(self) -> list:
params.oracle_log_sender.send_read_db_event("get_all_successful_items_for_day")
collection_name = str(datetime.date.today())
result_list = []
cursor = self.db[collection_name]
for document in cursor.find():
result_list.append(ReserveResultPojo.from_firestore_dict(document))
return result_list
def update_reserve_result(self, reserve_id: str, result: ResultEnum):
collection_name = str(datetime.date.today())
collection = self.db[collection_name]
collection.find_one_and_update({'_id': reserve_id}, {"$set": {"accepted": result.name}}, upsert=False)
def get_captcha_error_contacts_for_current_day(self) -> list: def get_captcha_error_contacts_for_current_day(self) -> list:
day = str(datetime.date.today()) day = str(datetime.date.today())
collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day
@@ -59,4 +76,4 @@ class MongoDbManager:
if __name__ == '__main__': if __name__ == '__main__':
db_manager = MongoDbManager() db_manager = MongoDbManager()
print(db_manager.get_captcha_error_contacts_for_current_day()) db_manager.update_reserve_result("welcome", ResultEnum.ACCEPTED)