support model and wait only for 30s for cookie used by csrf

This commit is contained in:
2025-07-10 19:58:31 +02:00
parent 3d05f739b4
commit c6ac87bdfa
6 changed files with 71 additions and 49 deletions
+47 -41
View File
@@ -6,11 +6,13 @@ from builtins import list
from concurrent.futures import ThreadPoolExecutor
from email.header import decode_header
from email.message import Message
from typing import Union
from imapclient import IMAPClient
from db.mongo_manager import MONGO_STORE_MANAGER
from excel_reader import read_contacts
from mail.mail_constants import DOMAIN_HOTMAIL, create_imap
from models.ReserveResultPojo import ReserveResultPojo
from models.mail_pojo import MailPojo, MailAddress
VALIDATION_URL_SUBJECT_fr = 'Validation de votre demande de rendez-vous'
@@ -204,21 +206,31 @@ class MailReader():
return mail_messages
def need_to_valid_url(url: str, successful_items) -> bool:
# return True
# if len(successful_items) == 0:
# return False
#
# Find the ReserveResultPojo object from persisted items of DB
#
def find_item_by_url(url: str, successful_items) -> Union[None, ReserveResultPojo]:
print("url is :" + url)
parts = url.split('/')
_id = parts[5]
if len(_id) == 6:
for item in successful_items:
if item.id == _id:
return item
return None
def need_to_valid_url(url: str, item: Union[ReserveResultPojo, None]) -> bool:
print("url is :" + url)
parts = url.split('/')
id = parts[5]
if len(id) == 6:
for item in successful_items:
if item.id == id:
if item.url_validated is not None:
return not item.url_validated
else:
# if url_validated is None
return True
if item:
if item.url_validated is not None:
return not item.url_validated
else:
# if url_validated is None
return True
return True
else:
print("id not valid:{}".format(id))
@@ -242,43 +254,37 @@ def need_to_check_email(mail: str, successful_items) -> bool:
def find_links_to_validate_from_mail_list(mail_list: list, logger):
if not mail_list:
return
# check time before start checking emails
if len(mail_list) > 0:
contact_to_book_list = MONGO_STORE_MANAGER.get_all_contact_to_book_list()
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
mails_messages = []
with ThreadPoolExecutor(max_workers=len(mail_list)) as executor:
for mail in mail_list:
# check whether we need to read mail
if need_to_check_email(mail.mail, successful_items):
mail_reader = MailReader(mail.mail, mail.password)
executor.submit(mail_reader.read_emails, mails_messages)
# for mail in mail_list:
# # check whether we need to read mail
# if need_to_check_email(mail.mail, successful_items):
# mail_reader = MailReader(mail.mail, mail.password)
# mail_reader.read_emails(mails_messages)
_refreshed_successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
for mail in mails_messages:
match = re.search(VALIDATION_URL_REGEX, mail.body)
if match:
url = match.group(0)
if need_to_valid_url(url, _refreshed_successful_items):
logger.info("need to validate url: " + url)
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.to_address,
_all_contact_list=contact_to_book_list)
else:
logger.info("do not need to click url --> {}".format(mail.mail_address))
contact_to_book_list = MONGO_STORE_MANAGER.get_all_contact_to_book_list()
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
mails_messages = []
with ThreadPoolExecutor(max_workers=len(mail_list)) as executor:
for mail in mail_list:
# check whether we need to read mail
if need_to_check_email(mail.mail, successful_items):
mail_reader = MailReader(mail.mail, mail.password)
executor.submit(mail_reader.read_emails, mails_messages)
_refreshed_successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
for mail in mails_messages:
match = re.search(VALIDATION_URL_REGEX, mail.body)
if match:
url = match.group(0)
_item = find_item_by_url(url, _refreshed_successful_items)
if need_to_valid_url(url, _item):
logger.info("need to validate url: " + url)
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.to_address, model=_item.model,
_all_contact_list=contact_to_book_list)
else:
logger.info("do not need to click url --> {}".format(mail.mail_address))
if __name__ == '__main__':
# mail_address1 = MailAddress(mail="tinagonzales685585@aol.com", password="yhihvdkrbxnksema")
# mail_list = [mail_address1]
contact_to_book_list = read_contacts(
# file_name="/Users/rdv/Desktop/contact_list_not_used_contacts.xlsx")
# file_name="/Users/lpan/Desktop/contact_list_not_used_contacts.xlsx")
# file_name="/Users/rdv/Desktop/real_name_contacts_100_hotmail.xlsx")
file_name="/Users/rdv/Desktop/contact_list_2025-06-23.xlsx")
file_name="/Users/lpan/Desktop/contact_list_2025-06-27_gmx.xlsx")
# file_name="/Users/rdv/Desktop/contact_list_all_studio.xlsx")
# file_name="/Users/rdv/Desktop/contact_list_all_studo_gmx_us.xlsx")
# file_name="/Users/rdv/Desktop/contact_list_2025-05-24.xlsx")