get csrf before send request

This commit is contained in:
2024-01-11 13:22:32 +01:00
parent 8b4a895cfb
commit 8063218514
4 changed files with 185 additions and 22 deletions
+35 -19
View File
@@ -1,14 +1,15 @@
import random
import time
from http.cookies import SimpleCookie
from db.mongo_manager import MONGO_STORE_MANAGER
from excel_reader import read_contacts
from models.contact_pojo import ContactPojo
from queue_message.receiver import Receiver
from workers.captcha_result_getter import CaptchaResultGetter, HERMES_REGISTER
from workers.sender import Sender
IPFIY = 'http://api.ipify.org'
HERMES_REGISTER = "https://rendezvousparis.hermes.com/client/register"
NGROK_TEST = "https://bcc6-193-164-156-53.ngrok-free.app"
@@ -34,7 +35,33 @@ def filter_contacts(_contact_list: list) -> list:
return _contact_list_to_book
def get_valid_csrf() -> str:
captchaResultGetter = CaptchaResultGetter()
_valid_cookie = captchaResultGetter.get_valid_cookie()
while _valid_cookie is None:
_valid_cookie = captchaResultGetter.get_valid_cookie()
new_csrf = None
while new_csrf is None:
simple_cookie = SimpleCookie()
simple_cookie.load(_valid_cookie)
new_cookies = {k: v.value for k, v in simple_cookie.items()}
new_coolies_str = ""
for key in new_cookies:
print(key)
new_coolies_str = new_coolies_str + key + "=" + new_cookies[key] + ";"
print(new_coolies_str)
valid_cookie = new_coolies_str + "app=eyJmbGFzaCI6e30sImNhY2hlZmxhc2giOltdLCJjc3JmU2VjcmV0IjoiYnRodHNYU1lvdnl4RzVGakpGRDZsQ0JtIn0=;policy=accepted;lang=fr;"
print(valid_cookie)
new_csrf = captchaResultGetter.get_csrf(valid_cookie)
time.sleep(2)
return new_csrf
valid_csrf = None
def on_message(ch, method, properties, body):
global valid_csrf
print(f" [x] Received {body}")
sender = Sender(body.decode("UTF-8"))
contact_list = read_contacts('/Users/panlei/Desktop/yahoo_aol_valid_26-2.xlsx')
@@ -46,10 +73,15 @@ def on_message(ch, method, properties, body):
# if not is_already_sent(con):
print(con.mail)
time.sleep(random.randint(1, 5))
can_continue = sender.send_request(HERMES_REGISTER, con)
if valid_csrf is None:
valid_csrf = get_valid_csrf()
can_continue = sender.send_request(HERMES_REGISTER, con, csrf=valid_csrf)
if not can_continue:
print("cannot continue")
print("cannot continue, valid_csrf is " + valid_csrf)
break
else:
print("can continue, will reset valid_csrf")
valid_csrf = None
# else:
# print(con.mail + "--> skip")
ch.basic_ack(delivery_tag=method.delivery_tag)
@@ -61,19 +93,3 @@ if __name__ == '__main__':
receiver = Receiver()
receiver.set_up_connection()
receiver.listen_to_queue(on_message)
# if __name__ == '__main__':
# sender = Sender()
# contact_list = read_contacts('/Users/panlei/Desktop/yahoo_aol_valid_26-1.xlsx')
# sub_contact_list = contact_list[200:300]
# for con in sub_contact_list:
# if not is_already_sent(con):
# time.sleep(random.randint(2, 10))
# can_continue = sender.send_request(HERMES_REGISTER, con)
# if not can_continue:
# print("cannot continue")
# break
# else:
# print(con.mail + "--> skip")
# print(con.mail)
# sender.send_request(HERMES_REGISTER, contact_list[-5])