log to file
This commit is contained in:
@@ -7,6 +7,7 @@ import time
|
||||
import pika
|
||||
|
||||
from db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from models.ReserveResultPojo import ReserveResultPojo
|
||||
from models.contact_pojo import ContactPojo
|
||||
from models.jsdata_le_pojo import JsDataLeTypePojo
|
||||
from models.jsdata_pojo import JsDataPojo
|
||||
@@ -29,14 +30,19 @@ def is_already_sent(contact: ContactPojo) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def filter_contacts(_contact_list: list) -> list:
|
||||
def filter_contacts(_contact_list: list, provided_list=[]) -> list:
|
||||
already_sent_contacts = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
already_sent_contacts.extend(provided_list)
|
||||
_contact_list_to_book = []
|
||||
for contact in _contact_list:
|
||||
_to_add = True
|
||||
for booked in already_sent_contacts:
|
||||
if contact.mail == booked.email:
|
||||
_to_add = False
|
||||
if isinstance(booked, ReserveResultPojo):
|
||||
if contact.mail == booked.email:
|
||||
_to_add = False
|
||||
else:
|
||||
if contact.mail == booked.mail:
|
||||
_to_add = False
|
||||
if _to_add:
|
||||
_contact_list_to_book.append(contact)
|
||||
|
||||
@@ -49,10 +55,13 @@ def is_open():
|
||||
|
||||
class AppointmentRequestSender(threading.Thread):
|
||||
def __init__(self, sub_contact_list: list, proxy_to_use_list, logger, cookiesPublisher: CookiesPublisher,
|
||||
just_send=False,
|
||||
queue_name=REQUEST_DATA_QUEUE):
|
||||
super().__init__()
|
||||
self.connection = None
|
||||
self.just_send = just_send
|
||||
self.logger = logger
|
||||
self.already_tried_contact_list = []
|
||||
self.cookiesPublisher = cookiesPublisher
|
||||
self.channel = None
|
||||
self.valid_csrf = None
|
||||
@@ -95,13 +104,17 @@ class AppointmentRequestSender(threading.Thread):
|
||||
_received_cookies = _received_dict["cookiesStr"]
|
||||
sender = Sender(_received_cookies, cookiesPublisher=self.cookiesPublisher, received_dict=_received_dict,
|
||||
proxy_to_use=_proxy_to_use, logger=self.logger)
|
||||
self.contact_list = filter_contacts(self.contact_list)
|
||||
# remove already sent contacts
|
||||
if self.just_send:
|
||||
self.contact_list = filter_contacts(self.contact_list, self.already_tried_contact_list)
|
||||
else:
|
||||
self.contact_list = filter_contacts(self.contact_list)
|
||||
# remove already booked contacts
|
||||
random.shuffle(self.contact_list)
|
||||
if len(self.contact_list) > 0 and is_open():
|
||||
captchaResultGetter = CaptchaResultGetter()
|
||||
self.logger.info("contact number is {}".format(len(self.contact_list)))
|
||||
self.contact_list = filter_contacts(self.contact_list)
|
||||
# self.contact_list = filter_contacts(self.contact_list)
|
||||
for con in self.contact_list:
|
||||
self.logger.info(con.mail)
|
||||
if self.valid_csrf is None:
|
||||
@@ -142,6 +155,7 @@ class AppointmentRequestSender(threading.Thread):
|
||||
# self.logger.info("new le type cookie is " + _new_le_cookies)
|
||||
sender.cookie_str = _new_le_cookies
|
||||
time.sleep(random.randint(1, 3))
|
||||
self.already_tried_contact_list.append(con)
|
||||
can_continue = sender.send_request(HERMES_REGISTER, js_data, con, csrf=self.valid_csrf)
|
||||
else:
|
||||
can_continue = RequestResult.COOKIES_ERROR
|
||||
|
||||
+6
-1
@@ -68,7 +68,8 @@ class Sender:
|
||||
'surname': contact.last_name.capitalize(), 'name': contact.first_name.capitalize(),
|
||||
'phone_country': "FR", 'phone_number': "+33 " + contact.phone, 'email': contact.mail,
|
||||
'passport_id': contact.passport, 'processing': 'on', 'cgu': 'on'}
|
||||
print(data)
|
||||
self.logger.info(data)
|
||||
self.logger.info("try to request for mail:{}".format(contact.mail))
|
||||
print("send request with cookie:{}".format(self.cookie_str))
|
||||
try:
|
||||
proxy_to_use = self.proxy_to_use
|
||||
@@ -96,6 +97,10 @@ class Sender:
|
||||
return RequestResult.SUCCESS
|
||||
else:
|
||||
print(response.text)
|
||||
if response.status_code == 403:
|
||||
# try to load seesion
|
||||
# session = HTMLSession()
|
||||
return RequestResult.BLOCKED
|
||||
return RequestResult.BLOCKED
|
||||
except Exception as Error:
|
||||
print(Error)
|
||||
|
||||
Reference in New Issue
Block a user