diff --git a/src/db/mongo_manager.py b/src/db/mongo_manager.py index eff817e..482c90f 100644 --- a/src/db/mongo_manager.py +++ b/src/db/mongo_manager.py @@ -93,6 +93,17 @@ class MongoDbManager: self.logger.info(error) return email_list + def get_invalid_emails(self) -> list: + collection_name = INVALID_EMAIL_LIST + email_list = [] + try: + collection_to_use = self.db[collection_name] + for document in collection_to_use.find(): + email_list.append(MailAddress.from_firestore_dict(document)) + except Exception as error: + self.logger.info(error) + return email_list + def insert_captcha_error_contact(self, contact: ContactPojo): day = str(datetime.date.today()) collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day @@ -192,6 +203,16 @@ class MongoDbManager: except Exception as error: self.logger.info(error) + def remove_email_from_destination_email_list(self, mail: MailAddress): + # DESTINATION_EMAIL_LIST + collection = self.db[DESTINATION_EMAIL_LIST] + to_delete = {'_id': mail.mail} + try: + collection.delete_one(to_delete) + except Exception as error: + self.logger.info(error) + print(error) + def remove_contact_from_black_list(self, contact: ContactPojo): collection_name = BLACK_LIST collection = self.db[collection_name] diff --git a/src/mail/mail_address_validator.py b/src/mail/mail_address_validator.py index d6aeb74..38ff71f 100644 --- a/src/mail/mail_address_validator.py +++ b/src/mail/mail_address_validator.py @@ -50,14 +50,19 @@ class MailAddressValidator(): print("{} is not valid".format(self.login)) -if __name__ == '__main__': - # address = "walter_chad1982@yahoo.com" - address = "ricejulie1979@yahoo.com" - # code = "xawbzyduwoquxsre" - code = "eybrvmzdmklizleh" - mail_list = MONGO_STORE_MANAGER.get_destination_emails() +def remove_invalid_email(): + invalid = MONGO_STORE_MANAGER.get_invalid_emails() + for mail in invalid: + MONGO_STORE_MANAGER.remove_email_from_destination_email_list(mail) + +def find_and_update_invalid_emails(): + mail_list = MONGO_STORE_MANAGER.get_destination_emails() with ThreadPoolExecutor(max_workers=20) as executor: for mail in mail_list: valiator = MailAddressValidator(mail.mail, mail.password) executor.submit(valiator.check_and_save_to_db) + + +if __name__ == '__main__': + remove_invalid_email()