Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b18804b2b | |||
| aa540ac622 | |||
| c9ee7d9a4f | |||
| f71650c347 | |||
| a690ca7fe5 | |||
| ea07867b67 | |||
| 1eedb1468e | |||
| 0870a040b6 | |||
| 8ae6a7593b | |||
| c6ac87bdfa | |||
| 343a14f6a2 | |||
| 62cdb55da2 |
+3
-1
@@ -83,7 +83,7 @@ class MongoDbManager:
|
||||
result_list.append(ContactPojo.from_firestore_dict(document))
|
||||
return result_list
|
||||
|
||||
def save_links_to_validate(self, link: str, mail_address: str, _all_contact_list: list):
|
||||
def save_links_to_validate(self, link: str, mail_address: str, model: str, _all_contact_list: list):
|
||||
collection_to_use = self.db[LINKS_TO_VALIDATE]
|
||||
updated_at = time.strftime("%H:%M:%S", time.localtime())
|
||||
_ip_country = "FR"
|
||||
@@ -98,6 +98,7 @@ class MongoDbManager:
|
||||
u'url': link,
|
||||
u'email': mail_address,
|
||||
u'serial': serial,
|
||||
u'model': model,
|
||||
u'ip_country': _ip_country,
|
||||
"updated_at": updated_at
|
||||
},
|
||||
@@ -106,6 +107,7 @@ class MongoDbManager:
|
||||
collection_to_use.replace_one(filter={'_id': link, }, replacement={
|
||||
u'url': link,
|
||||
u'serial': serial,
|
||||
u'model': model,
|
||||
u'ip_country': _ip_country,
|
||||
"updated_at": updated_at
|
||||
},
|
||||
|
||||
@@ -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")
|
||||
@@ -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'
|
||||
@@ -101,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()
|
||||
@@ -167,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'])
|
||||
@@ -204,21 +211,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))
|
||||
@@ -227,6 +244,8 @@ def need_to_valid_url(url: str, successful_items) -> 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:
|
||||
@@ -242,33 +261,33 @@ 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=200) 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)
|
||||
_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))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -278,8 +297,8 @@ if __name__ == '__main__':
|
||||
# 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/rdv/Desktop/contact_list_all_studio.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()
|
||||
@@ -299,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)
|
||||
|
||||
@@ -107,6 +107,9 @@ class ReserveResultPojo:
|
||||
if 'created_at' in source:
|
||||
created_at = source['created_at']
|
||||
result.created_at = created_at
|
||||
if 'model' in source:
|
||||
model = source['model']
|
||||
result.model = model
|
||||
if 'validated_at' in source:
|
||||
validated_at = source['validated_at']
|
||||
result.validated_at = validated_at
|
||||
|
||||
@@ -3,10 +3,13 @@ import json
|
||||
import random
|
||||
import threading
|
||||
import time
|
||||
from http.cookies import SimpleCookie
|
||||
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
|
||||
@@ -62,6 +65,24 @@ 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)
|
||||
if "x-xsrf-token" not in _simple_cookies:
|
||||
return None
|
||||
else:
|
||||
_xsfr_token = _simple_cookies["x-xsrf-token"].value
|
||||
return _xsfr_token
|
||||
|
||||
|
||||
class AppointmentRequestSender(threading.Thread):
|
||||
def __init__(self, sub_contact_list: list, logger, cookiesPublisher: CookiesPublisher,
|
||||
bakeUpCookiesPublisher: CookiesPublisher,
|
||||
@@ -213,9 +234,9 @@ class AppointmentRequestSender(threading.Thread):
|
||||
# 如果在发送请求时出现csrf被拦截的情况,那么就需要重新发布cookie以目前的队列中,因为这个cookie可能重新利用
|
||||
self.logger.info("csrf blocked, will republish cookie")
|
||||
self.cookiesPublisher.publish_body(_received_object)
|
||||
self.logger.info("csrf blocked, will wait 60 seconds")
|
||||
time.sleep(60)
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
self.logger.info("csrf blocked, will wait 30 seconds")
|
||||
time.sleep(30)
|
||||
elif can_continue is not None and can_continue == RequestResult.BLOCKED:
|
||||
self.logger.info("这个cookies可以给点链接用")
|
||||
self.bakeUpCookiesPublisher.publish_body(_received_object)
|
||||
@@ -252,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)
|
||||
|
||||
|
||||
|
||||
@@ -2,14 +2,13 @@ import json
|
||||
import random
|
||||
import re
|
||||
from typing import Union
|
||||
import requests
|
||||
|
||||
# import requests
|
||||
from curl_cffi import requests
|
||||
from models.jsdata_le_pojo import JsDataLeTypePojo
|
||||
from models.jsdata_pojo import JsDataPojo
|
||||
from models.result_pojo import RequestResult
|
||||
from utils.get_only_datadome_cookies import get_datadome_cookies, get_app_cookies, get_lang_cookies, \
|
||||
retain_only_dataome_cookies
|
||||
from workers.proxies_constants import PROXY_LIST_FR
|
||||
|
||||
API_KEY = "d66aaf490d8aa424a5175e1fbd1aadea"
|
||||
|
||||
|
||||
@@ -230,8 +230,8 @@ def validate_all_links(_contact_serial_list):
|
||||
# default_segment_number = 20
|
||||
_first_25_percent_links = link_to_validated[0:(int(len(all_link_list) / divided))]
|
||||
_first_25_percent_links = all_link_list
|
||||
_queue_name = MORNING_DATA_CACHE
|
||||
# _queue_name = MORNING_DATA_CACHE_BAK
|
||||
# _queue_name = MORNING_DATA_CACHE
|
||||
_queue_name = MORNING_DATA_CACHE_BAK
|
||||
# if len(all_link_list) > divided * default_segment_number:
|
||||
# _segment_number = default_segment_number
|
||||
# else:
|
||||
|
||||
Reference in New Issue
Block a user