start read_mails between 10:30 and 19:30
This commit is contained in:
+2
-1
@@ -5,7 +5,8 @@ from src.mail.mail_reader import read_mails
|
||||
|
||||
|
||||
def start_check_mail_job(sched):
|
||||
sched.add_job(read_mails, 'cron', day_of_week='mon-sat', minute='*/15', jitter=240, timezone='Europe/Paris',
|
||||
sched.add_job(read_mails, 'cron', day_of_week='mon-sat', hour='10-19', minute='*/15', jitter=240,
|
||||
timezone='Europe/Paris',
|
||||
max_instances=1)
|
||||
# sched.add_job(read_mails, 'cron', day_of_week='mon-sat', hour='11',
|
||||
# minute='30',
|
||||
|
||||
+34
-30
@@ -12,7 +12,9 @@ from src import params
|
||||
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from src.pojo.mail.mail_pojo import MailPojo, MailAddress
|
||||
from src.proxy.proxy_type import ProxyType
|
||||
from src.utils.timeutiles import is_time_between
|
||||
from src.workers.link_validator import LinkValidator
|
||||
from datetime import time
|
||||
|
||||
AOL_IMAP_SERVER = "imap.aol.com"
|
||||
YAHOO_IMAP_SERVER = "imap.mail.yahoo.com"
|
||||
@@ -25,7 +27,7 @@ HERMES_EMAIL = "no-reply@hermes.com"
|
||||
DOMAIN_163 = "163.com"
|
||||
DOMAIN_YAHOO = "yahoo.com"
|
||||
date_format = "%d-%b-%Y" # DD-Mon-YYYY e.g., 3-Mar-2014
|
||||
REDIRECTION_MAILS = "appointment2022@aol.com, chenpeijun@aol.com,hongjiang176@aol,ciyuexie@aol.com "
|
||||
REDIRECTION_MAILS = "appointment2022@aol.com, chenpeijun@aol.com,hongjiang176@aol,ciyuexie@aol.com"
|
||||
|
||||
|
||||
class MailReader():
|
||||
@@ -164,36 +166,38 @@ def need_to_check_email(mail: 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_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="ryan_meacham2856@yahoo.com", password="ulgggkodxqbvrpgm")
|
||||
# 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()
|
||||
mails_messages = []
|
||||
with ThreadPoolExecutor(max_workers=20) 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)
|
||||
# check time before start checking emails
|
||||
if is_time_between(time(10, 30), time(19, 30)):
|
||||
# get email address
|
||||
mail_list = MONGO_STORE_MANAGER.get_destination_emails()
|
||||
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="ryan_meacham2856@yahoo.com", password="ulgggkodxqbvrpgm")
|
||||
# mail_list = [mail_address3, mail_address2, mail_address1, mail_address4]
|
||||
# mail_list = [mail_address1]
|
||||
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
mails_messages = []
|
||||
with ThreadPoolExecutor(max_workers=20) 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)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=10) as executor:
|
||||
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, successful_items):
|
||||
url_validator = LinkValidator(url)
|
||||
print("need to validate url: " + url)
|
||||
executor.submit(url_validator.start_page, params.get_proxy(ProxyType.RESIDENTIAL), True)
|
||||
else:
|
||||
print("do not need to click url --> {}".format(mail.mail_address))
|
||||
with ThreadPoolExecutor(max_workers=10) as executor:
|
||||
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, successful_items):
|
||||
url_validator = LinkValidator(url)
|
||||
print("need to validate url: " + url)
|
||||
executor.submit(url_validator.start_page, params.get_proxy(ProxyType.RESIDENTIAL), True)
|
||||
else:
|
||||
print("do not need to click url --> {}".format(mail.mail_address))
|
||||
|
||||
|
||||
# check whether the url has already been clicked
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from datetime import datetime, time
|
||||
|
||||
|
||||
def is_time_between(begin_time, end_time, check_time=None):
|
||||
# If check time is not given, default to current UTC time
|
||||
check_time = check_time or datetime.now().time()
|
||||
if begin_time < end_time:
|
||||
return check_time >= begin_time and check_time <= end_time
|
||||
else: # crosses midnight
|
||||
return check_time >= begin_time or check_time <= end_time
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Original test case from OP
|
||||
print(is_time_between(time(10, 30), time(16, 30)))
|
||||
Reference in New Issue
Block a user