diff --git a/db/mongo_manager.py b/db/mongo_manager.py index 434c538..c2739af 100755 --- a/db/mongo_manager.py +++ b/db/mongo_manager.py @@ -11,7 +11,7 @@ from models.contact_pojo import ContactPojo from models.mail_pojo import MailAddress from models.regisered_user_pojo import RegisteredUserPojo -MONGO_DB_URL = "mongo.lpaconsulting.fr" +MONGO_DB_URL = "mongodb://mongo.lpaconsulting.fr/?timeoutMS=100000" CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_" BLACK_LIST = "BLACK_LIST" ACCEPTED_APPOINTMENT_LIST = "ACCEPTED_APPOINTMENT_LIST" diff --git a/queue_message/appointmentrequestsender.py b/queue_message/appointmentrequestsender.py index 1f6b834..aa0d361 100644 --- a/queue_message/appointmentrequestsender.py +++ b/queue_message/appointmentrequestsender.py @@ -65,7 +65,7 @@ def is_open(): class AppointmentRequestSender(threading.Thread): def __init__(self, sub_contact_list: list, logger, cookiesPublisher: CookiesPublisher, bakeUpCookiesPublisher: CookiesPublisher, - queue_name=REQUEST_DATA_QUEUE): + queue_name=REQUEST_DATA_QUEUE, stop_at_hour=11, stop_at_mins=30): super().__init__() self.connection = None self.logger = logger @@ -80,6 +80,8 @@ class AppointmentRequestSender(threading.Thread): self.queue_name = queue_name self.proxy_manager = ProxyManager(logger) self.already_read_emails = False + self.stop_at_hour = stop_at_hour + self.stop_at_mins = stop_at_mins def set_up_connection(self): self.connection = pika.BlockingConnection( @@ -93,7 +95,7 @@ class AppointmentRequestSender(threading.Thread): self.channel.start_consuming() def on_message(self, ch, method, properties, body): - self.check_and_stop_if_necessary(hour_to_check=11, mins_to_check=40) + self.check_and_stop_if_necessary(hour_to_check=self.stop_at_hour, mins_to_check=self.stop_at_mins) _message_count = self.cookiesPublisher.message_count() self.logger.info("message count in queue is {}".format(_message_count)) _received_object = body.decode("UTF-8") diff --git a/request_sender_test.py b/request_sender_test.py index 2fe77a2..f7c8093 100644 --- a/request_sender_test.py +++ b/request_sender_test.py @@ -42,10 +42,6 @@ def filter_contacts(_contact_list: list) -> list: return _contact_list_to_book -def is_open(): - return is_time_between(datetime.time(10, 30), datetime.time(19, 00)) - - count = 0 init_logger() logger = logging.getLogger() @@ -53,7 +49,7 @@ logger = logging.getLogger() logger.addHandler(logging.StreamHandler(stream=sys.stdout)) -def send_appointment_request(message_queue_name, _contact_list): +def send_appointment_request(message_queue_name, _contact_list, stop_at_hour=11, stop_at_mins=30): global count count = count + 1 for _contact in _contact_list: @@ -65,12 +61,14 @@ def send_appointment_request(message_queue_name, _contact_list): receiver = AppointmentRequestSender(sub_contact_list=_contact_list, queue_name=message_queue_name, cookiesPublisher=_cookiesPublisher, - bakeUpCookiesPublisher=_backUp_cookiesPublisher, logger=logger) + bakeUpCookiesPublisher=_backUp_cookiesPublisher, logger=logger, + stop_at_hour=stop_at_hour, stop_at_mins=stop_at_mins) print("count is " + str(count)) receiver.run() -def start_send_requests(thread_number, contact_list, data_queue_name=MORNING_DATA_CACHE): +def start_send_requests(thread_number, contact_list, data_queue_name=MORNING_DATA_CACHE, stop_at_hour=14, + stop_at_mins=56): print("start send requests") _contact_list_to_book = filter_contacts(contact_list) _segment_number = thread_number @@ -81,19 +79,20 @@ def start_send_requests(thread_number, contact_list, data_queue_name=MORNING_DAT logger.info("segment is {}".format(i)) _step = int(len(_contact_list_to_book) / _segment_number) _sublist = _contact_list_to_book[i * _step:_step * (i + 1)] - _thread1 = Thread(target=send_appointment_request, args=(data_queue_name, _sublist)) + _thread1 = Thread(target=send_appointment_request, args=(data_queue_name, _sublist, stop_at_hour, stop_at_mins)) thread_list.append(_thread1) _thread1.start() for _thread in thread_list: _thread.join() -def send_request_for_file_list(file_list: list[str], thread_number: int = 20, data_queue_name=MORNING_DATA_CACHE): +def send_request_for_file_list(file_list: list, thread_number: int = 20, data_queue_name=MORNING_DATA_CACHE, + stop_at_hour=11, stop_at_mins=30): for _file_path in file_list: logger.info("send request for file: " + _file_path) _contact_list = read_contacts(_file_path) start_send_requests(thread_number=thread_number, contact_list=_contact_list, - data_queue_name=data_queue_name) + data_queue_name=data_queue_name, stop_at_hour=stop_at_hour, stop_at_mins=stop_at_mins) if __name__ == '__main__': @@ -102,6 +101,6 @@ if __name__ == '__main__': # '~/Desktop/contact_list_2024-05-21.xlsx', # '~/Desktop/15_05_to_test.xlsx'] # file_list = ['~/Desktop/15_05_to_test.xlsx', '~/Desktop/16_05_to_test.xlsx'] - file_list = ['~/Desktop/contact_list_2024-06-28.xlsx'] - send_request_for_file_list(file_list=file_list, thread_number=10, - data_queue_name=MORNING_DATA_CACHE) + file_list = ['~/Desktop/contact_list_all.xlsx'] + send_request_for_file_list(file_list=file_list, thread_number=2, + data_queue_name=MORNING_DATA_CACHE, stop_at_hour=16, stop_at_mins=30)