add method to extract contact list with serial

This commit is contained in:
2024-12-12 23:32:41 +01:00
parent d884782cd8
commit 15286494d1
2 changed files with 33 additions and 5 deletions
+11
View File
@@ -88,6 +88,17 @@ class MongoDbManager:
except Exception as Error: except Exception as Error:
self.logger.info(Error) self.logger.info(Error)
def upload_contact_list_to_collection(self, contact_list: list, collection_name):
try:
collection_to_use = self.db[collection_name]
for contact in contact_list:
# collection_to_use.insert_one(contact.to_firestore_dict())
collection_to_use.replace_one(filter={'_id': contact.mail, }, replacement=contact.to_firestore_dict(),
upsert=True)
except Exception as Error:
self.logger.info(Error)
def get_all_accepted_appointments(self) -> list: def get_all_accepted_appointments(self) -> list:
collection_name = ACCEPTED_APPOINTMENT_LIST collection_name = ACCEPTED_APPOINTMENT_LIST
appointment_list_contacts = [] appointment_list_contacts = []
+22 -5
View File
@@ -1,6 +1,8 @@
from pathlib import Path
from src.db.mongo_manager import MONGO_STORE_MANAGER 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 from src.pojo.contact_pojo import ContactPojo
from src.utils.excel_reader import read_contacts
DOMAIN_TO_INCLUDE = ["aol.com", "yahoo.com", "gmx.de", "gmx.net", "inbox.lv"] DOMAIN_TO_INCLUDE = ["aol.com", "yahoo.com", "gmx.de", "gmx.net", "inbox.lv"]
@@ -32,11 +34,11 @@ def get_all_not_used_mails():
return not_used_emails return not_used_emails
def get_all_old_contact_set(): def get_all_old_contact_set(start_with="2024"):
all_collection_list = get_all_collections() all_collection_list = get_all_collections()
collection_to_check = [] collection_to_check = []
for col in all_collection_list: for col in all_collection_list:
if col.startswith('20'): if col.startswith(start_with):
collection_to_check.append(col) collection_to_check.append(col)
items_set = set() items_set = set()
for collection in collection_to_check: for collection in collection_to_check:
@@ -45,6 +47,15 @@ def get_all_old_contact_set():
return items_set return items_set
def get_all_contact_with_source_from():
_list_to_check = get_all_old_contact_set()
_to_return = []
for contact in _list_to_check:
if contact.serial is not None and len(contact.serial) > 0:
_to_return.append(contact)
return _to_return
def generate_not_used_contact_list(): def generate_not_used_contact_list():
not_used_mail_list = get_all_not_used_mails() not_used_mail_list = get_all_not_used_mails()
all_old_contact_set = get_all_old_contact_set() all_old_contact_set = get_all_old_contact_set()
@@ -63,6 +74,12 @@ def generate_not_used_contact_list():
return contact_list return contact_list
def upload_to_collection():
_contacts = read_contacts(str(Path.home()) + "/Desktop/contact_list_contacts_with_source.xlsx")
MONGO_STORE_MANAGER.upload_contact_list_to_collection(_contacts,"CONTACT_LIST_SERIAL_MAP")
if __name__ == '__main__': if __name__ == '__main__':
contact_to_save = generate_not_used_contact_list() upload_to_collection()
write_new_contacts_to_excel(valid_contacts=contact_to_save, file_name="all_old_not_used_contact") # contact_to_save = get_all_contact_with_source_from()
# write_new_contacts_to_excel(valid_contacts=contact_to_save, file_name="contacts_with_source")