Merge branch 'feature/IMAPClient' of bitbucket.org:panleicim/appointment_tool into feature/IMAPClient

This commit is contained in:
2023-04-11 14:58:25 +02:00
3 changed files with 52 additions and 22 deletions
+28 -16
View File
@@ -117,6 +117,7 @@ class MailReader():
print(body)
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.mail_address = self.login
mail_messages.append(mail)
return mail_messages
@@ -157,6 +158,7 @@ class MailReader():
def need_to_valid_url(url: str, successful_items) -> bool:
# return True
if len(successful_items) == 0:
return False
print("url is :" + url)
@@ -183,29 +185,39 @@ def need_to_check_email(mail: str, successful_items) -> bool:
return True
# return True
# get all the item with the current mail
filter_items = filter(lambda item: item.email == email, successful_items)
for item in filter_items:
if mail in item.email:
if item.url_validated is not None:
print("url_validated for {} is {}".format(mail, item.url_validated))
return not item.url_validated
else:
# if url-validated is none, need to check email
return True
# if the email has not been booked, we needn't read mails.
# return True
return False
filtered_items = list(filter(lambda item: item.email == mail, successful_items))
# has validated value
if len(filtered_items) > 0:
validated_items = list(filter(lambda filtered_item: filtered_item.url_validated is not None, filtered_items))
if len(validated_items) > 0:
return False
else:
return True
else:
return False
# for item in filtered_items:
# if mail in item.email:
# print("url_validated for {} is {}".format(mail, item.url_validated))
# if item.url_validated is not None:
# return not item.url_validated
# else:
# # if url-validated is none, need to check email
# return True
# # if the email has not been booked, we needn't read mails.
# # return True
# return False
def read_mails():
# check time before start checking emails
if is_time_between(time(7, 30), time(19, 30)):
# get email address
# mail_list = MONGO_STORE_MANAGER.get_destination_emails()
mail_address1 = MailAddress(mail="Saniremvazhaun@yahoo.com", password="hxwgldifdnuacoyr")
mail_list = MONGO_STORE_MANAGER.get_destination_emails()
# mail_address1 = MailAddress(mail="Saniremvazhaun@yahoo.com", password="hxwgldifdnuacoyr")
# mail_address1 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb")
# # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce")
mail_list = [mail_address1]
# mail_list = [mail_address1]
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
mails_messages = []
with ThreadPoolExecutor(max_workers=200) as executor:
@@ -228,7 +240,7 @@ def read_mails():
# else:
url = match.group(0)
if need_to_valid_url(url, successful_items):
MONGO_STORE_MANAGER.save_links_to_validate(url)
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.mail_address)
# url_validator = LinkValidator(url)
print("need to validate url: " + url)
# executor.submit(url_validator.start_page, params.get_proxy(ProxyType.OXYLABS), False)