From 9de56d7d036f7a694cd2d70916d27f9f628df3a0 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 4 Aug 2022 09:57:08 +0200 Subject: [PATCH] change contact start end number --- main.py | 2 +- src/mail/mail_reader.py | 58 ++++++++++++++++------------------- src/workers/link_validator.py | 3 +- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/main.py b/main.py index 4f22ea6..6ca3b94 100644 --- a/main.py +++ b/main.py @@ -62,5 +62,5 @@ def get_proxy(proxy_type=ProxyType.BRIGHT_DATA): if __name__ == '__main__': # 修改联系人行,结束联系人行 第三个参数store等于0的时候是随机,传入1的时候是总店 # start_book(744, 858, store_choose_state=1, mode=ModeEnum.AUTOMATIC, headless=False) - start_book(1171, 1387, store_choose_state=1, mode=ModeEnum.AUTOMATIC, headless=False) + start_book(1171, 1527, store_choose_state=1, mode=ModeEnum.AUTOMATIC, headless=False) # recheck_the_captcha_error_contacts(store_type=1, mode=ModeEnum.AUTOMATIC, on_no_contact_found=lambda: None, headless=False) diff --git a/src/mail/mail_reader.py b/src/mail/mail_reader.py index 4396854..25ef711 100644 --- a/src/mail/mail_reader.py +++ b/src/mail/mail_reader.py @@ -9,7 +9,7 @@ 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 @@ -28,7 +28,7 @@ class MailReader(): mail_list = [] imap = imaplib.IMAP4_SSL(AOL_IMAP_SERVER) # authenticate - imap.login(self.login, password) + imap.login(self.login, self.password) status, messages = imap.select("INBOX") # total number of emails messages = int(messages[0]) @@ -51,8 +51,8 @@ class MailReader(): from_address, subject_encoded = decode_header(msg.get("From"))[0] if isinstance(from_address, bytes): from_address = from_address.decode(subject_encoded) - print("Subject:", subject) print("From:", from_address) + print("Subject:", subject) # if the email message is multipart if msg.is_multipart(): # iterate over email parts @@ -81,16 +81,8 @@ class MailReader(): hermes_email = "no-reply@hermes.com" # account credentials -# username = "appointment2022@aol.com" -# password = "gyilpmvyyvlcaviq" - - -username = "chenpeijun@aol.com" -password = "ytifuwguknzifqyb" -# # -# -# username = "ciyuexie@aol.com" -# password = "czezlmmyypokdfce" +username = "appointment2022@aol.com" +password = "gyilpmvyyvlcaviq" def clean(text): @@ -121,21 +113,25 @@ def need_to_valid_url(url: str, successful_items) -> bool: # check whether the url has already been clicked if __name__ == '__main__': - mail_reader = MailReader(username, password) - successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day() - list = mail_reader.read_emails() - with ThreadPoolExecutor(max_workers=10) as executor: - for mail in list: - match = re.search(VALIDATION_URL_REGEX, mail.body) - if match: - url = match.group(0) - if need_to_valid_url(url, successful_items): - url_validator = LinkValidator(url) - print("need to validate url: " + url) - # .start_page(params.get_proxy(ProxyType.BRIGHT_DATA)) - executor.submit(url_validator.start_page, params.get_proxy(ProxyType.BRIGHT_DATA)) - else: - print("do not need to click url --> {}".format(mail)) - - # find link from mails - print(list) + mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq") + mail_address2 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb") + mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce") + mail_address4 = MailAddress(mail="hongjiang176@aol.com", password="ftzpscgzvwneelmn") + mail_list = [mail_address3, mail_address2, mail_address1, mail_address4] + # mail_list = [mail_address4] + for mail in mail_list: + mail_reader = MailReader(mail.mail, mail.password) + successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day() + list = mail_reader.read_emails() + with ThreadPoolExecutor(max_workers=10) as executor: + for mail in list: + match = re.search(VALIDATION_URL_REGEX, mail.body) + if match: + url = match.group(0) + if need_to_valid_url(url, successful_items): + url_validator = LinkValidator(url) + print("need to validate url: " + url) + # .start_page(params.get_proxy(ProxyType.BRIGHT_DATA)) + executor.submit(url_validator.start_page, params.get_proxy(ProxyType.BRIGHT_DATA), True) + else: + print("do not need to click url --> {}".format(mail)) diff --git a/src/workers/link_validator.py b/src/workers/link_validator.py index bad0a84..c56b6fd 100644 --- a/src/workers/link_validator.py +++ b/src/workers/link_validator.py @@ -81,7 +81,8 @@ class LinkValidator: self.browser.close() return None - def start_page(self, proxy): + def start_page(self, proxy, headless=False): + self.headless = headless self._run(proxy) def _on_page_loaded(self):