From 8e408473fb661dd9095151dc8b04e58b7d5526c5 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Fri, 2 Sep 2022 18:41:53 +0200 Subject: [PATCH] add en subject for emails --- src/mail/mail_confirmation.py | 12 ++++++----- src/mail/mail_reader.py | 18 +++++++++------- src/params.py | 4 ++++ src/workers/GeoCaptchSolver.py | 11 ++++++++-- src/workers/commandor_page.py | 38 ++++++++++++++++++++-------------- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/mail/mail_confirmation.py b/src/mail/mail_confirmation.py index 2869189..ffbd28b 100644 --- a/src/mail/mail_confirmation.py +++ b/src/mail/mail_confirmation.py @@ -16,7 +16,8 @@ from src.pojo.mail.mail_pojo import MailPojo AOL_IMAP_SERVER = "imap.aol.com" IMAP_SERVER_163 = "imap.163.com" -CONFIRMATION_SUBJECT = 'Votre rendez-vous est' +CONFIRMATION_SUBJECT_FR = 'Votre rendez-vous est' +CONFIRMATION_SUBJECT_EN = 'appointment is confirmed' HERMES_EMAIL = "no-reply@hermes.com" DOMAIN_163 = "163.com" @@ -45,17 +46,18 @@ class MailConfirmationReader(): mail_list = [] print("read mails from {}".format(self.login)) # self.show_folders(imap) - mail_list.extend(self._get_messages_from_folder(imap)) + mail_list.extend(self._get_messages_from_folder(imap, CONFIRMATION_SUBJECT_FR)) + mail_list.extend(self._get_messages_from_folder(imap, CONFIRMATION_SUBJECT_EN)) # close the connection and logout imap.close() imap.logout() mails_messages.extend(mail_list) return mail_list - def _get_messages_from_folder(self, imap, folder="INBOX") -> list: + def _get_messages_from_folder(self, imap, subject, folder="INBOX") -> list: imap.select(folder) mail_messages = [] - typ, data = imap.search(None, '(SUBJECT "{}" SINCE "{}")'.format(CONFIRMATION_SUBJECT, + typ, data = imap.search(None, '(SUBJECT "{}" SINCE "{}")'.format(subject, datetime.datetime.today().strftime( date_format))) for i in data[0].split(): @@ -95,7 +97,7 @@ class MailConfirmationReader(): else: body = msg.get_payload(decode=True).decode() print(body) - if CONFIRMATION_SUBJECT in subject: + if CONFIRMATION_SUBJECT_FR in subject or CONFIRMATION_SUBJECT_EN in subject: mail = MailPojo(subject=subject, body=body, from_address=from_address) mail.mail_address = self.login mail_messages.append(mail) diff --git a/src/mail/mail_reader.py b/src/mail/mail_reader.py index 34dad3e..f86834d 100644 --- a/src/mail/mail_reader.py +++ b/src/mail/mail_reader.py @@ -10,13 +10,14 @@ from builtins import list from src import params from src.db.mongo_manager import MONGO_STORE_MANAGER -from src.pojo.mail.mail_pojo import MailPojo +from src.pojo.mail.mail_pojo import MailPojo, MailAddress from src.proxy.proxy_type import ProxyType from src.workers.link_validator import LinkValidator AOL_IMAP_SERVER = "imap.aol.com" IMAP_SERVER_163 = "imap.163.com" -VALIDATION_URL_SUBJECT = 'Validation de votre demande de rendez-vous' +VALIDATION_URL_SUBJECT_fr = 'Validation de votre demande de rendez-vous' +VALIDATION_URL_SUBJECT_EN = 'Please confirm your appointment' VALIDATION_URL_REGEX = """https:\/\/rendezvousparis.hermes.com\/client\/register\/[A-Z0-9]+\/validate.code=[A-Z0-9]+""" HERMES_EMAIL = "no-reply@hermes.com" @@ -54,7 +55,8 @@ class MailReader(): # (\HasNoChildren) = "Inbox" # (\Sent \HasNoChildren) = "Sent" # (\Trash \HasNoChildren) = "Trash" - mail_list.extend(self._get_messages_from_folder(imap)) + mail_list.extend(self._get_messages_from_folder(imap, subject=VALIDATION_URL_SUBJECT_fr)) + mail_list.extend(self._get_messages_from_folder(imap, subject=VALIDATION_URL_SUBJECT_EN)) # mail_list.extend(self._get_messages_from_folder(imap, folder="Bulk")) # close the connection and logout imap.close() @@ -62,10 +64,10 @@ class MailReader(): mails_messages.extend(mail_list) return mail_list - def _get_messages_from_folder(self, imap, folder="INBOX") -> list: + def _get_messages_from_folder(self, imap, subject, folder="INBOX") -> list: imap.select(folder) mail_messages = [] - typ, data = imap.search(None, '(SUBJECT "{}" SINCE "{}")'.format(VALIDATION_URL_SUBJECT, + typ, data = imap.search(None, '(SUBJECT "{}" SINCE "{}")'.format(subject, datetime.datetime.today().strftime( date_format))) for i in data[0].split(): @@ -105,7 +107,7 @@ class MailReader(): else: body = msg.get_payload(decode=True).decode() print(body) - if VALIDATION_URL_SUBJECT in subject: + if VALIDATION_URL_SUBJECT_fr in subject or VALIDATION_URL_SUBJECT_EN in subject: mail = MailPojo(subject=subject, body=body, from_address=from_address) mail_messages.append(mail) return mail_messages @@ -140,12 +142,12 @@ def need_to_valid_url(url: str, successful_items) -> bool: def read_mails(): # get email address mail_list = MONGO_STORE_MANAGER.get_destination_emails() - # # mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq") + # mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq") # # mail_address2 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb") # # mail_address2 = MailAddress(mail="sdfgfhgf1986@aol.com", password="fjwcgvhxxlywqfwm") # # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce") # # mail_address4 = MailAddress(mail="hongjiang176@aol.com", password="ftzpscgzvwneelmn") - # mail_address4 = MailAddress(mail="ribka_puchkova@aol.com", password="aqvsozoyifbixtdc") + # mail_address4 = MailAddress(mail="likegirlpassed@aol.com", password="xjgohjpclvgpnhbz") # mail_list = [mail_address3, mail_address2, mail_address1, mail_address4] # mail_list = [mail_address4] successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day() diff --git a/src/params.py b/src/params.py index b4a245c..593735e 100644 --- a/src/params.py +++ b/src/params.py @@ -48,6 +48,10 @@ def get_random_id_number_for_proxy() -> str: print("The randomly generated string is : " + str(ran)) # print the random data return id_number +def get_random_wait_time() -> float: + wait_time = random.randint(0, 10) / 10.0 * 1 + return wait_time + DEVICES = ['iPad (gen 6)', 'iPad (gen 6) landscape', 'iPad (gen 7)', 'iPad (gen 7) landscape', 'iPad Mini', 'iPad Mini landscape', 'iPad Pro 11', 'iPad Pro 11 landscape', 'iPhone 6', 'iPhone 6 landscape', diff --git a/src/workers/GeoCaptchSolver.py b/src/workers/GeoCaptchSolver.py index 8360648..4553bbf 100644 --- a/src/workers/GeoCaptchSolver.py +++ b/src/workers/GeoCaptchSolver.py @@ -1,12 +1,18 @@ import re +import uuid +from uuid import UUID import requests import speech_recognition as sr +import time import wget +from src.params import get_random_wait_time + WAV_FILE_REGEX = "https:[\/a-z0-9.-]+.wav" -number_text_dict = {'eight': 8, 'zero': 0, 'one': 1, 'won': 1, 'to': 2, 'two': 2, 'three': 3, 'four': 4, 'for': 4, +number_text_dict = {'eight': 8, 'take': 8, 'zero': 0, 'one': 1, 'won': 1, 'to': 2, 'two': 2, 'three': 3, 'four': 4, + 'for': 4, 'five': 5, 'six': 6, 'seven': 7, 'nine': 9} @@ -36,7 +42,7 @@ class GeoCaptchaSolver: # wav_url = match.group(0) # print("wav file " + wav_url) response = requests.get(wav_url) - file_name = wav_url.split("/")[-1] + file_name = str(uuid.uuid4()) + wav_url.split("/")[-1] wget.download(wav_url, file_name) open(file_name, "wb").write(response.content) r = sr.Recognizer() @@ -83,6 +89,7 @@ class GeoCaptchaSolver: input_fileds[info.index].value = info.number;} """, {'index': index, 'number': number}) index = index + 1 + time.sleep(get_random_wait_time()) self.iframe.query_selector(".audio-captcha-verify-button").evaluate("""(btn)=>{ btn.click()};""") diff --git a/src/workers/commandor_page.py b/src/workers/commandor_page.py index 7005ca7..a90b96b 100644 --- a/src/workers/commandor_page.py +++ b/src/workers/commandor_page.py @@ -12,6 +12,7 @@ from typing import Union from src import params, definitions from src.db.mongo_manager import MONGO_STORE_MANAGER +from src.params import get_random_wait_time from src.pojo.ModeEnum import ModeEnum from src.pojo.ReserveResultPojo import ReserveResultPojo, PublishType from src.pojo.contact_pojo import ContactPojo @@ -47,11 +48,6 @@ OTP_TIMEOUT = 240 PAGE_TIMEOUT = 40000 -def get_random_wait_time() -> float: - wait_time = random.randint(0, 10) / 10.0 * 1 - return wait_time - - class CommandorPage: tls = TlsPlaywright() @@ -132,8 +128,8 @@ class CommandorPage: def start_browser(self, proxy, pwright, device) -> Union[str, None]: try: - self.browser = pwright.webkit.launch(headless=self.headless, timeout=PAGE_TIMEOUT) - # self.browser = pwright.webkit.launch(headless=self.headless, timeout=PAGE_TIMEOUT, proxy=proxy) + # self.browser = pwright.webkit.launch(headless=self.headless, timeout=PAGE_TIMEOUT) + self.browser = pwright.webkit.launch(headless=self.headless, timeout=PAGE_TIMEOUT, proxy=proxy) # userAgent = random.choice(params.firefox_user_agent_list) simulated_mobile = pwright.devices[device] userAgent = simulated_mobile['user_agent'] @@ -178,11 +174,15 @@ class CommandorPage: def solve_datadome_captcha(self): print("solve_datadome_captcha") - # time.sleep(2) - self._click_audio_btn() - time.sleep(20) - solver = GeoCaptchaSolver(self.page) - solver.solve() + time.sleep(2) + success = self._click_audio_btn() + if success: + time.sleep(16) + time.sleep(get_random_wait_time()) + solver = GeoCaptchaSolver(self.page) + solver.solve() + else: + self.termine() def _on_page_loaded(self): # time.sleep(40000) @@ -248,12 +248,18 @@ class CommandorPage: except Exception as error: self.logger.error(error) - def _click_audio_btn(self): + def _click_audio_btn(self) -> bool: time.sleep(get_random_wait_time()) iframe = self.page.query_selector('iframe').content_frame() - iframe.query_selector('#captcha__audio__button').click() - time.sleep(2) - iframe.query_selector('.audio-captcha-play-button').evaluate("""(btn)=>{btn.click()}""") + audio_button = iframe.query_selector('#captcha__audio__button') + if audio_button: + audio_button.click() + time.sleep(2) + iframe.query_selector('.audio-captcha-play-button').evaluate("""(btn)=>{btn.click()}""") + return True + else: + print("audio_button not found") + return False # self.page.evaluate("""{ # let surname = document.getElementById('captcha__audio__button');