add method to merge contacts

This commit is contained in:
2024-03-31 18:10:01 +02:00
parent 283bbb9a74
commit bf13860b40
3 changed files with 33 additions and 7 deletions
+26 -6
View File
@@ -4,11 +4,11 @@ import random
import xlsxwriter
from src.db.mongo_manager import MONGO_STORE_MANAGER
from src.utils.excel_reader import read_contacts, fr_phone_number_prefix, get_random_fr_phone_numbers
from src.utils.excel_reader import read_contacts, fr_phone_number_prefix, get_random_fr_phone_numbers, ExcelHelper
def upload_contacts_list():
_contacts_to_book = read_contacts("/Users/panlei/Desktop/contact_list_2024-03-23.xlsx")
_contacts_to_book = read_contacts("/Users/panlei/Desktop/contact_list_2024-03-30.xlsx")
return _contacts_to_book
@@ -19,7 +19,7 @@ def fix_phone_number_format(file_path):
if _contact.phone[0:2] not in fr_phone_number_prefix:
print(_contact)
_contact.phone = get_random_fr_phone_numbers()
write_new_contacts_to_excel(_contact_list, file_name="23_03_to_test")
write_new_contacts_to_excel(_contact_list, file_name="25_03_to_test")
def write_new_contacts_to_excel(valid_contacts: list, file_name=str(datetime.date.today())):
@@ -66,6 +66,18 @@ def generate_valid_contact_list_for_day():
write_new_contacts_to_excel(_contact_to_save)
def merge_contact_list_files(file_list: list, final_file_name="merged_contact_list"):
_all_contact_list = []
for file in file_list:
_all_contact_list.extend(read_contacts(file))
for _con in _all_contact_list:
_con.store = "random"
print(len(_all_contact_list))
_list_without_duplicate = list(set(_all_contact_list))
print(len(_list_without_duplicate))
write_new_contacts_to_excel(_list_without_duplicate, file_name=final_file_name)
def generate_all_contact_list():
_all_contacts = MONGO_STORE_MANAGER.get_all_contacts_to_book()
random.shuffle(_all_contacts)
@@ -76,8 +88,16 @@ def generate_all_contact_list():
# 把新的联系人存到网上
if __name__ == '__main__':
contacts_to_book = upload_contacts_list()
MONGO_STORE_MANAGER.upload_contact_list(contacts_to_book)
# contacts_to_book = upload_contacts_list()
# MONGO_STORE_MANAGER.upload_contact_list(contacts_to_book)
# generate_valid_contact_list_for_day()
# generate_all_contact_list()
# fix_phone_number_format("/Users/panlei/Desktop/23_03_to_test.xlsx")
merge_contact_list_files(
["/Users/panlei/Desktop/contact_list_2024-03-29.xlsx",
"/Users/panlei/Desktop/contact_list_2024-03-27.xlsx",
"/Users/panlei/Desktop/contact_list_2024-03-28.xlsx",
"/Users/panlei/Desktop/contact_list_2024-03-26.xlsx",
"/Users/panlei/Desktop/contact_list_2024-03-25.xlsx",
"/Users/panlei/Desktop/contact_list_2024-03-23.xlsx",
"/Users/panlei/Desktop/contact_list_2024-03-22.xlsx"])
# fix_phone_number_format("/Users/panlei/Desktop/25_03_to_test.xlsx")