republish valid cookie
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import pika
|
||||
|
||||
QUEUE_HOST = "appointment.lpaconsulting.fr"
|
||||
REQUEST_DATA_QUEUE = 'REQUEST_DATA'
|
||||
credentials = pika.PlainCredentials('appointment', 'ZyuhJZ2xEYWhElhpJjy7YEpZGZwNYJz2fHIu')
|
||||
|
||||
|
||||
class CookiesPublisher:
|
||||
|
||||
def __init__(self):
|
||||
self.connection = None
|
||||
self.channel = None
|
||||
|
||||
def set_up_connection(self):
|
||||
self.connection = pika.BlockingConnection(
|
||||
pika.ConnectionParameters(host=QUEUE_HOST, port=5672, credentials=credentials))
|
||||
self.channel = self.connection.channel()
|
||||
# self.channel.queue_declare(queue=REQUEST_DATA_QUEUE, durable=True)
|
||||
|
||||
def publish_body(self, body: str):
|
||||
self.channel.basic_publish(exchange='', routing_key=REQUEST_DATA_QUEUE, body=body)
|
||||
@@ -67,8 +67,9 @@ def get_valid_csrf() -> str:
|
||||
|
||||
|
||||
class LinkValidatorReceiver(threading.Thread):
|
||||
def __init__(self):
|
||||
def __init__(self, linkpojo_list: list):
|
||||
self.connection = None
|
||||
self.linkpojo_list = linkpojo_list
|
||||
self.channel = None
|
||||
|
||||
def set_up_connection(self):
|
||||
@@ -83,41 +84,42 @@ class LinkValidatorReceiver(threading.Thread):
|
||||
|
||||
def on_message(self, ch, method, properties, body):
|
||||
print(f" [x] Received {body}")
|
||||
link_list = MONGO_STORE_MANAGER.get_links_to_validate()
|
||||
# remove already booked contacts
|
||||
random.shuffle(link_list)
|
||||
link = random.choice(link_list)
|
||||
_link_validator = LinkValidator(body.decode("UTF-8"), link_to_validate=link)
|
||||
_link_validator.send_request()
|
||||
|
||||
# if len(self.contact_list) > 0:
|
||||
# print("contact number is {}".format(len(self.contact_list)))
|
||||
# for con in self.contact_list:
|
||||
# sender = Sender(body.decode("UTF-8"))
|
||||
# # if not is_already_sent(con):
|
||||
# print(con.mail)
|
||||
# # time.sleep(random.randint(1, 5))
|
||||
# if self.valid_csrf is None:
|
||||
# self.valid_csrf = get_valid_csrf()
|
||||
# can_continue = sender.send_request(HERMES_REGISTER, con, csrf=self.valid_csrf)
|
||||
# if not can_continue:
|
||||
# print("cannot continue, valid_csrf is " + self.valid_csrf)
|
||||
# break
|
||||
# else:
|
||||
# print("can continue, will reset valid_csrf")
|
||||
# self.valid_csrf = None
|
||||
# # else:
|
||||
# # print(con.mail + "--> skip")
|
||||
# ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
# else:
|
||||
# print("empty list")
|
||||
# random.shuffle(link_list)
|
||||
# link = random.choice(link_list)
|
||||
# _link_validator = LinkValidator(body.decode("UTF-8"), link_to_validate=link)
|
||||
# _link_validator.send_request()
|
||||
#
|
||||
# print(f" [x] Received {body}")
|
||||
# sender = Sender(body.decode("UTF-8"))
|
||||
# remove already booked contacts
|
||||
random.shuffle(self.linkpojo_list)
|
||||
if len(self.linkpojo_list) > 0:
|
||||
print("contact number is {}".format(len(self.linkpojo_list)))
|
||||
for con in self.linkpojo_list:
|
||||
# if not is_already_sent(con):
|
||||
print(con.email)
|
||||
can_continue = self.send_request(HERMES_REGISTER, con, csrf=self.valid_csrf)
|
||||
if not can_continue:
|
||||
print("cannot continue, valid_csrf is " + self.valid_csrf)
|
||||
break
|
||||
else:
|
||||
print("can continue, will reset valid_csrf")
|
||||
self.valid_csrf = None
|
||||
# else:
|
||||
# print(con.mail + "--> skip")
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
else:
|
||||
print("empty list")
|
||||
|
||||
def run(self):
|
||||
print(threading.currentThread().name + " starts")
|
||||
self.set_up_connection()
|
||||
self.listen_to_queue(self.on_message)
|
||||
self.channel.start_consuming()
|
||||
# if __name__ == '__main__':
|
||||
# receiver = Receiver()
|
||||
# receiver.set_up_connection()
|
||||
# receiver.listen_to_queue(on_message)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
link_list = MONGO_STORE_MANAGER.get_links_to_validate()
|
||||
receiver = LinkValidatorReceiver(link_list)
|
||||
receiver.run()
|
||||
|
||||
@@ -7,6 +7,7 @@ import pika
|
||||
|
||||
from db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from models.contact_pojo import ContactPojo
|
||||
from queue_message.CookiesPublisher import CookiesPublisher
|
||||
from workers.captcha_result_getter import CaptchaResultGetter, HERMES_REGISTER
|
||||
from workers.sender import Sender
|
||||
|
||||
@@ -66,8 +67,10 @@ def get_valid_csrf() -> str:
|
||||
|
||||
|
||||
class Receiver(threading.Thread):
|
||||
def __init__(self, sub_contact_list: list):
|
||||
def __init__(self, sub_contact_list: list, cookiesPublisher: CookiesPublisher):
|
||||
super().__init__()
|
||||
self.connection = None
|
||||
self.cookiesPublisher = cookiesPublisher
|
||||
self.channel = None
|
||||
self.valid_csrf = None
|
||||
self.contact_list = sub_contact_list
|
||||
@@ -84,21 +87,22 @@ class Receiver(threading.Thread):
|
||||
|
||||
def on_message(self, ch, method, properties, body):
|
||||
print(f" [x] Received {body}")
|
||||
sender = Sender(body.decode("UTF-8"))
|
||||
sender = Sender(body.decode("UTF-8"), cookiesPublisher=self.cookiesPublisher)
|
||||
self.contact_list = filter_contacts(self.contact_list)
|
||||
# remove already booked contacts
|
||||
random.shuffle(self.contact_list)
|
||||
if len(self.contact_list) > 0:
|
||||
captchaResultGetter = CaptchaResultGetter()
|
||||
print("contact number is {}".format(len(self.contact_list)))
|
||||
for con in self.contact_list:
|
||||
# if not is_already_sent(con):
|
||||
print(con.mail)
|
||||
# time.sleep(random.randint(1, 5))
|
||||
if self.valid_csrf is None:
|
||||
self.valid_csrf = get_valid_csrf()
|
||||
self.valid_csrf = captchaResultGetter.get_csrf(body.decode("UTF-8"))
|
||||
can_continue = sender.send_request(HERMES_REGISTER, con, csrf=self.valid_csrf)
|
||||
if not can_continue:
|
||||
print("cannot continue, valid_csrf is " + self.valid_csrf)
|
||||
print("cannot continue, valid_csrf is " + str(self.valid_csrf))
|
||||
break
|
||||
else:
|
||||
print("can continue, will reset valid_csrf")
|
||||
|
||||
Reference in New Issue
Block a user