create method go get not used contacts

This commit is contained in:
Lei PAN
2024-06-26 21:17:15 +02:00
parent 2acff3d7a4
commit 9e9d6b666e
2 changed files with 69 additions and 1 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ class ReserveResultPojo:
ua = "" ua = ""
def __hash__(self): def __hash__(self):
return hash("{}_{}_{}_{}_{}".format(self.mail, self.first_name, self.last_name, self.phone, self.passport)) return hash("{}".format(self.mail))
@staticmethod @staticmethod
def from_firestore_dict(source): def from_firestore_dict(source):
@@ -0,0 +1,68 @@
from src.db.mongo_manager import MONGO_STORE_MANAGER
from src.person_name.contact_manager import write_new_contacts_to_excel
from src.pojo.contact_pojo import ContactPojo
DOMAIN_TO_INCLUDE = ["aol.com", "yahoo.com", "gmx.de", "gmx.net", "inbox.lv"]
def get_all_collections():
return MONGO_STORE_MANAGER.list_collection_names()
def need_to_check_mail(mail_address):
for domain in DOMAIN_TO_INCLUDE:
if domain in mail_address:
return True
return False
def get_all_not_used_mails():
all_emails = MONGO_STORE_MANAGER.get_destination_emails()
all_valid_contact_list = MONGO_STORE_MANAGER.get_all_contacts_to_book()
not_used_emails = []
for mail_item in all_emails:
if need_to_check_mail(mail_item.mail):
_need_to_add = False
for valid_contact in all_valid_contact_list:
if valid_contact.mail == mail_item.mail:
_need_to_add = True
break
if _need_to_add:
not_used_emails.append(mail_item)
return not_used_emails
def get_all_old_contact_set():
all_collection_list = get_all_collections()
collection_to_check = []
for col in all_collection_list:
if col.startswith('20'):
collection_to_check.append(col)
items_set = set()
for collection in collection_to_check:
items_for_day = MONGO_STORE_MANAGER.get_all_successful_items_for_one_day(collection)
items_set.update(items_for_day)
return items_set
def generate_not_used_contact_list():
not_used_mail_list = get_all_not_used_mails()
all_old_contact_set = get_all_old_contact_set()
contact_list = []
for mail_item in not_used_mail_list:
print("mail is " + mail_item.mail)
for contact in all_old_contact_set:
if contact.mail == mail_item.mail:
if contact.phone is not None and len(contact.phone) > 0:
new_contact = ContactPojo(mail=mail_item.mail, phone_number=contact.phone,
passport_number=contact.passport,
last_name=contact.last_name, first_name=contact.first_name,
store="random")
contact_list.append(new_contact)
break
return contact_list
if __name__ == '__main__':
contact_to_save = generate_not_used_contact_list()
write_new_contacts_to_excel(valid_contacts=contact_to_save, file_name="all_old_not_used_contact")