cookies directly from tag.js not work
This commit is contained in:
+37
-73
@@ -1,11 +1,13 @@
|
||||
import random
|
||||
import time
|
||||
from concurrent.futures import as_completed
|
||||
from concurrent.futures.thread import ThreadPoolExecutor
|
||||
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 queue_message.receiver import Receiver, filter_contacts
|
||||
from workers.captcha_result_getter import CaptchaResultGetter, HERMES_REGISTER
|
||||
from workers.sender import Sender
|
||||
|
||||
@@ -13,90 +15,52 @@ IPFIY = 'http://api.ipify.org'
|
||||
NGROK_TEST = "https://bcc6-193-164-156-53.ngrok-free.app"
|
||||
|
||||
|
||||
def is_already_sent(contact: ContactPojo) -> bool:
|
||||
already_sent_contacts = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
for required_contact in already_sent_contacts:
|
||||
if contact.mail == required_contact.email:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def filter_contacts(_contact_list: list) -> list:
|
||||
already_sent_contacts = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
_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 _to_add:
|
||||
_contact_list_to_book.append(contact)
|
||||
|
||||
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:
|
||||
valid_cookie = None
|
||||
if _valid_cookie is not 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)
|
||||
if new_csrf is None:
|
||||
_valid_cookie = None
|
||||
while _valid_cookie is None:
|
||||
_valid_cookie = captchaResultGetter.get_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/rdv/Desktop/08_01_24_valid.xlsx')
|
||||
def handle_cookie(cookie: str):
|
||||
contact_list = read_contacts('/Users/panlei/Desktop/real_name_contacts_77_14_01_2024.xlsx')
|
||||
print(f" [x] Received {cookie}")
|
||||
sender = Sender(cookie)
|
||||
contact_list = filter_contacts(contact_list)
|
||||
# remove already booked contacts
|
||||
sub_contact_list = filter_contacts(contact_list)
|
||||
random.shuffle(sub_contact_list)
|
||||
if len(sub_contact_list) > 0:
|
||||
print("contact number is {}".format(len(sub_contact_list)))
|
||||
for con in sub_contact_list:
|
||||
random.shuffle(contact_list)
|
||||
if len(contact_list) > 0:
|
||||
print("contact number is {}".format(len(contact_list)))
|
||||
for con in contact_list:
|
||||
# if not is_already_sent(con):
|
||||
print(con.mail)
|
||||
# time.sleep(random.randint(1, 5))
|
||||
if valid_csrf is None:
|
||||
valid_csrf = get_valid_csrf()
|
||||
can_continue = sender.send_request(HERMES_REGISTER, con, csrf=valid_csrf)
|
||||
# if self.valid_csrf is None:
|
||||
# self.valid_csrf = get_valid_csrf()
|
||||
can_continue = sender.send_request(HERMES_REGISTER, con)
|
||||
if not can_continue:
|
||||
print("cannot continue, valid_csrf is " + valid_csrf)
|
||||
print("cannot continue, valid_csrf is ")
|
||||
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)
|
||||
else:
|
||||
print("empty list")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
receiver = Receiver()
|
||||
receiver.set_up_connection()
|
||||
receiver.listen_to_queue(on_message)
|
||||
captchaResultGetter = CaptchaResultGetter()
|
||||
ch_valid_cookies = captchaResultGetter.get_valid_ch_cookie()
|
||||
valid_cookies = captchaResultGetter.get_valid_cookie(old_valid_cookie=ch_valid_cookies)
|
||||
print(ch_valid_cookies)
|
||||
valid_cookies = valid_cookies + ";app=eyJmbGFzaCI6e30sImNhY2hlZmxhc2giOltdLCJjc3JmU2VjcmV0IjoidVdfTVhUbnhmbnBYQVlJTDlKTUtCZDQtIiwiYXBwb2ludG1lbnRfY29kZSI6IlRGOTlOVSIsImJsb2NrX3JlZ2lzdHJhdGlvbiI6ZmFsc2V9;policy=accepted;lang=fr;app.sig=JzJN6KT0vNudm29rf3toN_Cx8wI;"
|
||||
valid_cookies = valid_cookies.replace(" ", "").replace("Path=/;", "").replace("Secure;", "").replace(
|
||||
"SameSite=None;", "").replace("Domain=.hermes.com;", "").replace("Max-Age=31536000;", "")
|
||||
print(valid_cookies)
|
||||
|
||||
handle_cookie(valid_cookies)
|
||||
# contact_list = read_contacts('/Users/panlei/Desktop/yahoo_aol_26_3_valid.xlsx')
|
||||
# contact_list = filter_contacts(contact_list)
|
||||
# index = int(len(contact_list) / 2)
|
||||
# first_half = contact_list[:index]
|
||||
# second_half = contact_list[index:]
|
||||
# to_book = [first_half, second_half]
|
||||
# for li in to_book:
|
||||
# receiver = Receiver(contact_list)
|
||||
# receiver.run()
|
||||
# receiver.set_up_connection()
|
||||
# receiver.listen_to_queue(receiver.on_message)
|
||||
|
||||
Reference in New Issue
Block a user