Merge branch 'feature/stop_at_hour' of bitbucket.org:panleicim/appointment_request into feature/stop_at_hour
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ from models.contact_pojo import ContactPojo
|
|||||||
from models.mail_pojo import MailAddress
|
from models.mail_pojo import MailAddress
|
||||||
from models.regisered_user_pojo import RegisteredUserPojo
|
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_"
|
CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_"
|
||||||
BLACK_LIST = "BLACK_LIST"
|
BLACK_LIST = "BLACK_LIST"
|
||||||
ACCEPTED_APPOINTMENT_LIST = "ACCEPTED_APPOINTMENT_LIST"
|
ACCEPTED_APPOINTMENT_LIST = "ACCEPTED_APPOINTMENT_LIST"
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ def is_open():
|
|||||||
class AppointmentRequestSender(threading.Thread):
|
class AppointmentRequestSender(threading.Thread):
|
||||||
def __init__(self, sub_contact_list: list, logger, cookiesPublisher: CookiesPublisher,
|
def __init__(self, sub_contact_list: list, logger, cookiesPublisher: CookiesPublisher,
|
||||||
bakeUpCookiesPublisher: CookiesPublisher,
|
bakeUpCookiesPublisher: CookiesPublisher,
|
||||||
queue_name=REQUEST_DATA_QUEUE):
|
queue_name=REQUEST_DATA_QUEUE, stop_at_hour=11, stop_at_mins=30):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
@@ -80,6 +80,8 @@ class AppointmentRequestSender(threading.Thread):
|
|||||||
self.queue_name = queue_name
|
self.queue_name = queue_name
|
||||||
self.proxy_manager = ProxyManager(logger)
|
self.proxy_manager = ProxyManager(logger)
|
||||||
self.already_read_emails = False
|
self.already_read_emails = False
|
||||||
|
self.stop_at_hour = stop_at_hour
|
||||||
|
self.stop_at_mins = stop_at_mins
|
||||||
|
|
||||||
def set_up_connection(self):
|
def set_up_connection(self):
|
||||||
self.connection = pika.BlockingConnection(
|
self.connection = pika.BlockingConnection(
|
||||||
@@ -93,7 +95,7 @@ class AppointmentRequestSender(threading.Thread):
|
|||||||
self.channel.start_consuming()
|
self.channel.start_consuming()
|
||||||
|
|
||||||
def on_message(self, ch, method, properties, body):
|
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()
|
_message_count = self.cookiesPublisher.message_count()
|
||||||
self.logger.info("message count in queue is {}".format(_message_count))
|
self.logger.info("message count in queue is {}".format(_message_count))
|
||||||
_received_object = body.decode("UTF-8")
|
_received_object = body.decode("UTF-8")
|
||||||
|
|||||||
+12
-13
@@ -43,10 +43,6 @@ def filter_contacts(_contact_list: list) -> list:
|
|||||||
return _contact_list_to_book
|
return _contact_list_to_book
|
||||||
|
|
||||||
|
|
||||||
def is_open():
|
|
||||||
return is_time_between(datetime.time(10, 30), datetime.time(19, 00))
|
|
||||||
|
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
init_logger()
|
init_logger()
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -54,7 +50,7 @@ logger = logging.getLogger()
|
|||||||
logger.addHandler(logging.StreamHandler(stream=sys.stdout))
|
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
|
global count
|
||||||
count = count + 1
|
count = count + 1
|
||||||
for _contact in _contact_list:
|
for _contact in _contact_list:
|
||||||
@@ -66,12 +62,14 @@ def send_appointment_request(message_queue_name, _contact_list):
|
|||||||
receiver = AppointmentRequestSender(sub_contact_list=_contact_list,
|
receiver = AppointmentRequestSender(sub_contact_list=_contact_list,
|
||||||
queue_name=message_queue_name,
|
queue_name=message_queue_name,
|
||||||
cookiesPublisher=_cookiesPublisher,
|
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))
|
print("count is " + str(count))
|
||||||
receiver.run()
|
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")
|
print("start send requests")
|
||||||
_contact_list_to_book = filter_contacts(contact_list)
|
_contact_list_to_book = filter_contacts(contact_list)
|
||||||
_segment_number = thread_number
|
_segment_number = thread_number
|
||||||
@@ -82,20 +80,21 @@ def start_send_requests(thread_number, contact_list, data_queue_name=MORNING_DAT
|
|||||||
logger.info("segment is {}".format(i))
|
logger.info("segment is {}".format(i))
|
||||||
_step = int(len(_contact_list_to_book) / _segment_number)
|
_step = int(len(_contact_list_to_book) / _segment_number)
|
||||||
_sublist = _contact_list_to_book[i * _step:_step * (i + 1)]
|
_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)
|
thread_list.append(_thread1)
|
||||||
_thread1.start()
|
_thread1.start()
|
||||||
for _thread in thread_list:
|
for _thread in thread_list:
|
||||||
_thread.join()
|
_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:
|
for _file_path in file_list:
|
||||||
logger.info("send request for file: " + _file_path)
|
logger.info("send request for file: " + _file_path)
|
||||||
_contact_list = read_contacts(_file_path)
|
_contact_list = read_contacts(_file_path)
|
||||||
random.shuffle(_contact_list)
|
random.shuffle(_contact_list)
|
||||||
start_send_requests(thread_number=thread_number, contact_list=_contact_list,
|
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__':
|
if __name__ == '__main__':
|
||||||
@@ -104,6 +103,6 @@ if __name__ == '__main__':
|
|||||||
# '~/Desktop/contact_list_2024-05-21.xlsx',
|
# '~/Desktop/contact_list_2024-05-21.xlsx',
|
||||||
# '~/Desktop/15_05_to_test.xlsx']
|
# '~/Desktop/15_05_to_test.xlsx']
|
||||||
# file_list = ['~/Desktop/15_05_to_test.xlsx', '~/Desktop/16_05_to_test.xlsx']
|
# file_list = ['~/Desktop/15_05_to_test.xlsx', '~/Desktop/16_05_to_test.xlsx']
|
||||||
file_list = ['~/Desktop/contact_list_2024-07-25.xlsx']
|
file_list = ['~/Desktop/contact_list_all.xlsx']
|
||||||
send_request_for_file_list(file_list=file_list, thread_number=100,
|
send_request_for_file_list(file_list=file_list, thread_number=2,
|
||||||
data_queue_name=MORNING_DATA_CACHE)
|
data_queue_name=MORNING_DATA_CACHE, stop_at_hour=16, stop_at_mins=30)
|
||||||
|
|||||||
Reference in New Issue
Block a user