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',
|
||||
|
||||
@@ -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"
|
||||
@@ -164,16 +166,18 @@ def need_to_check_email(mail: str, successful_items) -> bool:
|
||||
|
||||
|
||||
def read_mails():
|
||||
# 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_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]
|
||||
# mail_list = [mail_address1]
|
||||
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
mails_messages = []
|
||||
with ThreadPoolExecutor(max_workers=20) as executor:
|
||||
|
||||
@@ -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