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
+2 -1
View File
@@ -256,11 +256,12 @@ class MongoDbManager:
collection.find_one_and_update({'_id': id}, {"$set": {"url_validated": state, "validated_at": validated_at}},
upsert=False)
def save_links_to_validate(self, link: str):
def save_links_to_validate(self, link: str, mail_address: str):
collection_to_use = self.db[LINKS_TO_VALIDATE]
updated_at = time.strftime("%H:%M:%S", time.localtime())
collection_to_use.replace_one(filter={'_id': link, }, replacement={
u'url': link,
u'email': mail_address,
"updated_at": updated_at
},
upsert=True)
+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)
+22 -5
View File
@@ -43,12 +43,29 @@ class ReserveResultPojo:
publish_type = source['type']
if publish_type:
publish_type = PublishType[publish_type]
phone = source['phone']
url = source['url']
id = source['id']
if 'phone' in source:
phone = source['phone']
else:
phone = ""
if 'url' in source:
url = source['url']
else:
url = ""
if 'id' in source:
id = source['id']
else:
id = ""
email = source['email']
lastName = source['lastName']
firstName = source['firstName']
if 'lastName' in source:
lastName = source['lastName']
else:
lastName = ""
if 'firstName' in source:
firstName = source['firstName']
else:
firstName = ""
result = ReserveResultPojo(type=publish_type, phone=phone,
url=url, email=email,
firstName=firstName, lastName=lastName)