Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b18804b2b | |||
| aa540ac622 | |||
| c9ee7d9a4f | |||
| f71650c347 | |||
| a690ca7fe5 | |||
| ea07867b67 | |||
| 1eedb1468e | |||
| 0870a040b6 | |||
| 8ae6a7593b | |||
| 343a14f6a2 | |||
| 62cdb55da2 |
@@ -0,0 +1,123 @@
|
||||
import logging
|
||||
import random
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from mail.mail_reader_all_contacts import find_links_to_validate_from_mail_list
|
||||
from models.mail_pojo import MailAddress
|
||||
|
||||
host = "https://authhk.bhdata.com:30015/bhmailer?uid=482391396&sign=32d7748da00047b9a1054c81a5750365"
|
||||
|
||||
HERMES_EMAIL = "no-reply@hermes.com"
|
||||
|
||||
|
||||
def get_api_info():
|
||||
_time = str(int(time.time() * 1000))
|
||||
_api_info = host + "&act=getApiInfo&t=" + _time
|
||||
print(_api_info)
|
||||
res = requests.get(_api_info, verify=False)
|
||||
print(res.text)
|
||||
|
||||
|
||||
def get_mail(mail: str):
|
||||
_time = str(int(time.time() * 1000))
|
||||
_hermes_mail = "Votre demande de rendez-vous"
|
||||
_api_info = host + "&act=getMail&email={}&title={}&t={}".format(mail, _hermes_mail, _time)
|
||||
print(_api_info)
|
||||
res = requests.get(_api_info, verify=False)
|
||||
print(res.text)
|
||||
|
||||
|
||||
def check_mail(mail: str):
|
||||
print("check_mail called for {}".format(mail))
|
||||
_time = str(int(time.time() * 1000))
|
||||
_hermes_mail = HERMES_EMAIL
|
||||
_subjet = "Votre rendez-vous est confirmé"
|
||||
_api_info = host + "&act=checkMail&email={}&from={}&title={}&t={}".format(mail, _hermes_mail, _subjet, _time)
|
||||
print(_api_info)
|
||||
res = requests.get(_api_info, verify=False)
|
||||
print(res.text)
|
||||
|
||||
|
||||
def check_appointment_link_mail(mail: str):
|
||||
print("check_mail called for {}".format(mail))
|
||||
_time = str(int(time.time() * 1000))
|
||||
_hermes_mail = HERMES_EMAIL
|
||||
_subjet = "Votre demande de rendez-vous"
|
||||
_api_info = host + "&act=checkMail&email={}&from={}&title={}&t={}".format(mail, _hermes_mail, _subjet, _time)
|
||||
print(_api_info)
|
||||
res = requests.get(_api_info, verify=False)
|
||||
print(res.text)
|
||||
|
||||
|
||||
def get_account(mail: str):
|
||||
_time = str(int(time.time() * 1000))
|
||||
_api_info = host + "&act=getAccount&email={}&t={}".format(mail, _time)
|
||||
print(_api_info)
|
||||
res = requests.get(_api_info, verify=False)
|
||||
print(res.text)
|
||||
|
||||
|
||||
def filter_mail_with_links(_mail_list_to_filter):
|
||||
_new_mail_list = []
|
||||
_link_to_validate_list = MONGO_STORE_MANAGER.get_links_to_validate()
|
||||
for _mail in _mail_list_to_filter:
|
||||
_to_add = True
|
||||
for _link in _link_to_validate_list:
|
||||
if _link.email == _mail:
|
||||
_to_add = False
|
||||
if _to_add:
|
||||
_new_mail_list.append(_mail)
|
||||
return _new_mail_list
|
||||
|
||||
|
||||
def get_mail_list_to_check():
|
||||
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
_mail_list = []
|
||||
for _item in successful_items:
|
||||
if _item.url_validated is None or _item.url_validated != True:
|
||||
_mail_list.append(_item.email)
|
||||
return _mail_list
|
||||
|
||||
|
||||
def check_confirmed_mails():
|
||||
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
# _mail_list = []
|
||||
for _item in successful_items:
|
||||
if "outlook" in _item.email or "hotmail" in _item.email:
|
||||
check_mail(_item.email)
|
||||
time.sleep(random.randint(1, 5))
|
||||
|
||||
|
||||
def check_all_need_to_check_emails():
|
||||
logger = logging.getLogger()
|
||||
_mail_list_before_filter = get_mail_list_to_check()
|
||||
_mails = filter_mail_with_links(_mail_list_before_filter)
|
||||
for _mail in _mails:
|
||||
if "outlook.com" in _mail or "hotmail.com" in _mail:
|
||||
check_mail(_mail)
|
||||
time.sleep(2)
|
||||
|
||||
_mail_list = [MailAddress("saigecong1990@pissmail.com", "cvExXKOP8oY1D@")]
|
||||
find_links_to_validate_from_mail_list(_mail_list, logger)
|
||||
|
||||
|
||||
def try_to_check_all_mails():
|
||||
logger = logging.getLogger()
|
||||
_mail_list_before_filter = get_mail_list_to_check()
|
||||
_mails = filter_mail_with_links(_mail_list_before_filter)
|
||||
for _mail in _mails:
|
||||
if "outlook.com" in _mail or "hotmail.com" in _mail:
|
||||
check_appointment_link_mail(_mail)
|
||||
time.sleep(2)
|
||||
_mail_list = [MailAddress("saigecong1990@pissmail.com", "cvExXKOP8oY1D@")]
|
||||
find_links_to_validate_from_mail_list(_mail_list, logger)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# check_all_need_to_check_emails()
|
||||
try_to_check_all_mails()
|
||||
# check_confirmed_mails()
|
||||
# check_appointment_link_mail("hcunlvi533@outlook.com")
|
||||
@@ -103,7 +103,10 @@ class MailReader():
|
||||
folder_list = self.show_folders(imap)
|
||||
for folder in folder_list:
|
||||
print("folder is " + folder)
|
||||
mail_list.extend(self._get_messages_from_folder_for_imapclient(imap, folder=folder))
|
||||
if folder == "Sent" or folder == "Drafts":
|
||||
pass
|
||||
else:
|
||||
mail_list.extend(self._get_messages_from_folder_for_imapclient(imap, folder=folder))
|
||||
if not isImapClient:
|
||||
imap.close()
|
||||
imap.logout()
|
||||
@@ -169,10 +172,12 @@ class MailReader():
|
||||
search_terms = 'SINCE "{}"'.format(
|
||||
datetime.datetime.today().strftime(
|
||||
date_format))
|
||||
print("search terms is " + search_terms)
|
||||
print("{}: search terms is {}".format(self.login,search_terms))
|
||||
imap.select_folder(folder)
|
||||
messages = imap.search(['SINCE', datetime.datetime.today()])
|
||||
print("%d messages from our best friend" % len(messages))
|
||||
print("{}: {} messages from our best friend".format(self.login, len(messages)))
|
||||
if len(messages) ==0:
|
||||
return mail_messages
|
||||
for uid, message_data in imap.fetch(messages, 'RFC822').items():
|
||||
try:
|
||||
email_message = email.message_from_bytes(message_data[b'RFC822'])
|
||||
@@ -239,6 +244,8 @@ def need_to_valid_url(url: str, item: Union[ReserveResultPojo, None]) -> bool:
|
||||
|
||||
def need_to_check_email(mail: str, successful_items) -> bool:
|
||||
print("successful_items size is " + str(len(successful_items)))
|
||||
if mail =="saigecong1990@pissmail.com":
|
||||
return True
|
||||
filtered_items = list(filter(lambda item: item.email == mail, successful_items))
|
||||
# has validated value
|
||||
if len(filtered_items) > 0:
|
||||
@@ -260,7 +267,7 @@ def find_links_to_validate_from_mail_list(mail_list: list, logger):
|
||||
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:
|
||||
with ThreadPoolExecutor(max_workers=200) as executor:
|
||||
for mail in mail_list:
|
||||
# check whether we need to read mail
|
||||
if need_to_check_email(mail.mail, successful_items):
|
||||
@@ -274,7 +281,10 @@ def find_links_to_validate_from_mail_list(mail_list: list, logger):
|
||||
_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,
|
||||
_model = ""
|
||||
if _item:
|
||||
_model = _item.model
|
||||
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.to_address, model=_model,
|
||||
_all_contact_list=contact_to_book_list)
|
||||
else:
|
||||
logger.info("do not need to click url --> {}".format(mail.mail_address))
|
||||
@@ -284,8 +294,11 @@ 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/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_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="~/Desktop/contact_list_2025-07-11.xlsx")
|
||||
file_name="~/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")
|
||||
all_mail_list = MONGO_STORE_MANAGER.get_destination_emails()
|
||||
@@ -305,4 +318,5 @@ if __name__ == '__main__':
|
||||
if _to_add:
|
||||
filter_mail.append(mail_pojo)
|
||||
filter_mail.append(MailAddress("saigecong1990@pissmail.com", "cvExXKOP8oY1D@"))
|
||||
# filter_mail = [MailAddress("saigecong1990@pissmail.com", "cvExXKOP8oY1D@")]
|
||||
find_links_to_validate_from_mail_list(filter_mail, logger)
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import Optional
|
||||
import pika
|
||||
|
||||
from db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from mail.lan_mail_helper import check_mail, check_all_need_to_check_emails
|
||||
from mail.mail_reader_all_contacts import find_links_to_validate_from_mail_list
|
||||
from models.ReserveResultPojo import ReserveResultPojo
|
||||
from models.contact_pojo import ContactPojo
|
||||
@@ -64,6 +65,14 @@ def is_open():
|
||||
return is_time_between(datetime.time(10, 30), datetime.time(19, 00))
|
||||
|
||||
|
||||
def check_ms_mails(_mail_list_filtered):
|
||||
print("check_ms_mails() called.")
|
||||
check_all_need_to_check_emails()
|
||||
# for _mail in _mail_list_filtered:
|
||||
# if "outlook.com" in _mail.mail or "hotmail.com" in _mail.mail:
|
||||
# check_mail(_mail.mail)
|
||||
|
||||
|
||||
def get_xsfr_token_from_cookies(cookies_str: str) -> Optional[str]:
|
||||
_simple_cookies = SimpleCookie()
|
||||
_simple_cookies.load(cookies_str)
|
||||
@@ -264,6 +273,7 @@ class AppointmentRequestSender(threading.Thread):
|
||||
self.logger.info("will get mail from " + mail.mail)
|
||||
_mail_list_filtered.append(mail)
|
||||
self.logger.info("will call find_links_to_validate_from_mail_list, size = " + str(len(_mail_list_filtered)))
|
||||
check_ms_mails(_mail_list_filtered)
|
||||
find_links_to_validate_from_mail_list(_mail_list_filtered, self.logger)
|
||||
self.already_read_emails = True
|
||||
else:
|
||||
|
||||
@@ -10,9 +10,7 @@ from models.contact_pojo import ContactPojo
|
||||
from queue_message.CookiesPublisher import CookiesPublisher, SHARED_OBJECT, TEST_QUEUE, MORNING_DATA_CACHE, \
|
||||
MORNING_DATA_CACHE_2, MORNING_DATA_CACHE_BAK
|
||||
from queue_message.appointmentrequestsender import AppointmentRequestSender
|
||||
from utiles import is_time_between
|
||||
from utils.AppLogging import init_logger
|
||||
from workers.proxies_constants import MOBILE_PROXY_LIST_FR
|
||||
|
||||
|
||||
def is_already_sent(contact: ContactPojo) -> bool:
|
||||
@@ -103,6 +101,8 @@ if __name__ == '__main__':
|
||||
# '~/Desktop/contact_list_2024-05-21.xlsx',
|
||||
# '~/Desktop/15_05_to_test.xlsx']
|
||||
# file_list = ['~/Desktop/15_05_to_test.xlsx', '~/Desktop/16_05_to_test.xlsx']
|
||||
file_list = ['~/Desktop/contact_list_2025-06-09_2.xlsx']
|
||||
send_request_for_file_list(file_list=file_list, thread_number=10,
|
||||
file_list = ['~/Desktop/contact_list_2025-07-11.xlsx']
|
||||
# file_list = ['~/Desktop/contact_list_all_studio.xlsx']
|
||||
# file_list = ['~/Desktop/real_name_contacts_100_27_06.xlsx']
|
||||
send_request_for_file_list(file_list=file_list, thread_number=20,
|
||||
data_queue_name=MORNING_DATA_CACHE, stop_at_hour=19, stop_at_mins=50)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
curl_cffi==0.7.1
|
||||
openpyxl
|
||||
+2
-2
@@ -6,8 +6,8 @@ from request_sender_test import send_request_for_file_list
|
||||
|
||||
|
||||
def start_book_appointment():
|
||||
file_list = ['~/Desktop/contact_list_2025-06-09_2.xlsx']
|
||||
send_request_for_file_list(file_list=file_list, thread_number=30,
|
||||
file_list = ['~/Desktop/contact_list_2025-07-11.xlsx']
|
||||
send_request_for_file_list(file_list=file_list, thread_number=60,
|
||||
data_queue_name=MORNING_DATA_CACHE, stop_at_hour=11, stop_at_mins=20)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user