187 lines
8.5 KiB
Python
Executable File
187 lines
8.5 KiB
Python
Executable File
import datetime
|
|
import random
|
|
|
|
import xlsxwriter
|
|
|
|
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
|
from src.person_name.cython_extract_methods import filter_already_validated_contacts, read_pinyin_list_from_file
|
|
from src.pojo.contact_pojo import ContactPojo
|
|
from src.utils.contacts.generate_random_passport_id import get_random_passport_id_number
|
|
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/lpan/Desktop/contact_list_2024-09-25.xlsx")
|
|
return _contacts_to_book
|
|
|
|
|
|
def fix_phone_number_format(file_path):
|
|
_contact_list = read_contacts(file_path)
|
|
for _contact in _contact_list:
|
|
if _contact.first_name is None or len(_contact.first_name) == 0:
|
|
print(_contact)
|
|
# _contact.last_name.replace("\xa0", " ")
|
|
original_last_name = _contact.last_name
|
|
_contact.last_name = original_last_name.replace("\xa0", " ").split(" ")[0]
|
|
_contact.first_name = original_last_name.replace("\xa0", " ").split(" ")[1]
|
|
print(_contact)
|
|
if _contact.phone.startswith('7'):
|
|
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="15_05_to_test")
|
|
|
|
|
|
def generate_contact_from_mail_list(mail_list_file,
|
|
name_list_file_path="all_new_name_list.txt"):
|
|
execl_reader = ExcelHelper()
|
|
mail_list = execl_reader.read_mails_and_pwd(mail_list_file)
|
|
print("mail_list size is {}".format(len(mail_list)))
|
|
# print("mail_list size before filter is {}".format(len(mail_list)))
|
|
filter_already_validated_contacts(mail_list)
|
|
print("mail_list size after filter is {}".format(len(mail_list)))
|
|
generate_contacts = []
|
|
pinyin_name_list = read_pinyin_list_from_file(name_list_file_path)
|
|
random.shuffle(pinyin_name_list)
|
|
print(pinyin_name_list[0])
|
|
for mail in mail_list:
|
|
phone_number = get_random_fr_phone_numbers()
|
|
passport_number = get_random_passport_id_number()
|
|
name = random.choice(pinyin_name_list)
|
|
last_name = name.split(" ")[0]
|
|
first_name = name.split(" ")[1]
|
|
contact = ContactPojo(mail=mail.mail, phone_number=phone_number, passport_number=passport_number,
|
|
last_name=last_name, first_name=first_name, store="random")
|
|
generate_contacts.append(contact)
|
|
write_new_contacts_to_excel(generate_contacts)
|
|
|
|
|
|
def write_new_contacts_to_excel(valid_contacts: list, file_name=str(datetime.date.today())):
|
|
row = 0
|
|
col = 0
|
|
# Create a workbook and add a worksheet.
|
|
workbook = xlsxwriter.Workbook('contact_list_{}.xlsx'.format(file_name))
|
|
header_data = ['name', 'phone', 'passport', 'email', 'store', 'ip_country', 'ua']
|
|
worksheet = workbook.add_worksheet()
|
|
header_format = workbook.add_format({'bold': True})
|
|
|
|
for col_num, data in enumerate(header_data):
|
|
worksheet.write(row, col_num, data, header_format)
|
|
row = row + 1
|
|
for info in valid_contacts:
|
|
# Iterate over the data and write it out row by row.
|
|
worksheet.write(row, col, "{} {}".format(info.last_name, info.first_name))
|
|
worksheet.write(row, col + 1, info.phone)
|
|
worksheet.write(row, col + 2, info.passport)
|
|
worksheet.write(row, col + 3, info.mail)
|
|
worksheet.write(row, col + 4, info.store)
|
|
worksheet.write(row, col + 5, info.ip_country)
|
|
worksheet.write(row, col + 6, info.ua)
|
|
row += 1
|
|
workbook.close()
|
|
|
|
|
|
def generate_valid_contact_list_for_day(segment_number=1):
|
|
_valid_contact_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
|
_all_contacts = MONGO_STORE_MANAGER.get_all_contacts_to_book()
|
|
_contact_to_save = []
|
|
for _contact in _valid_contact_list:
|
|
# _contact.store = "faubourg"
|
|
_contact.store = "random"
|
|
if _contact.last_name is None or len(_contact.last_name) == 0:
|
|
for _true_contact in _all_contacts:
|
|
if _true_contact.mail == _contact.mail:
|
|
_contact.last_name = _true_contact.last_name
|
|
_contact.phone = _true_contact.phone
|
|
_contact.passport = _true_contact.passport
|
|
_contact.first_name = _true_contact.first_name
|
|
|
|
if _contact.url_validated:
|
|
if _contact.last_name is not None and len(_contact.last_name) > 0:
|
|
_need_to_save = True
|
|
# remove the duplicated items
|
|
for _added_item in _contact_to_save:
|
|
if (_added_item.mail == _contact.mail
|
|
and _added_item.phone == _contact.phone
|
|
and _added_item.passport == _contact.passport
|
|
and _added_item.last_name == _contact.last_name
|
|
and _added_item.first_name == _contact.first_name):
|
|
_need_to_save = False
|
|
if _need_to_save:
|
|
_contact_to_save.append(_contact)
|
|
_contact_to_save_list = _contact_to_save
|
|
write_new_contacts_to_excel(_contact_to_save_list)
|
|
for i in range(0, segment_number):
|
|
_step = int(len(_contact_to_save_list) / segment_number)
|
|
_sublist = _contact_to_save_list[i * _step:_step * (i + 1)]
|
|
_file_name = str(datetime.date.today()) + "_" + str(i + 1)
|
|
write_new_contacts_to_excel(_sublist, file_name=_file_name)
|
|
|
|
|
|
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)
|
|
for _contact in _all_contacts:
|
|
_contact.store = "random"
|
|
write_new_contacts_to_excel(_all_contacts, file_name="all")
|
|
|
|
|
|
def get_old_validated_contact_list():
|
|
_valid_contact_list = MONGO_STORE_MANAGER.get_all_successful_items_for_one_day("2024-09-10")
|
|
_all_contacts = MONGO_STORE_MANAGER.get_all_contacts_to_book()
|
|
_contact_to_save = []
|
|
for _contact in _valid_contact_list:
|
|
# _contact.store = "faubourg"
|
|
_contact.store = "random"
|
|
if _contact.last_name is None or len(_contact.last_name) == 0:
|
|
for _true_contact in _all_contacts:
|
|
if _true_contact.mail == _contact.mail:
|
|
_contact.last_name = _true_contact.last_name
|
|
_contact.phone = _true_contact.phone
|
|
_contact.passport = _true_contact.passport
|
|
_contact.first_name = _true_contact.first_name
|
|
|
|
if _contact.url_validated:
|
|
if _contact.last_name is not None and len(_contact.last_name) > 0:
|
|
_need_to_save = True
|
|
# remove the duplicated items
|
|
for _added_item in _contact_to_save:
|
|
if (_added_item.mail == _contact.mail
|
|
and _added_item.phone == _contact.phone
|
|
and _added_item.passport == _contact.passport
|
|
and _added_item.last_name == _contact.last_name
|
|
and _added_item.first_name == _contact.first_name):
|
|
_need_to_save = False
|
|
if _need_to_save:
|
|
_contact_to_save.append(_contact)
|
|
_contact_to_save_list = _contact_to_save
|
|
write_new_contacts_to_excel(_contact_to_save_list)
|
|
|
|
|
|
# 把新的联系人存到网上
|
|
if __name__ == '__main__':
|
|
contacts_to_book = upload_contacts_list()
|
|
MONGO_STORE_MANAGER.upload_contact_list(contacts_to_book)
|
|
# print("start at {}".format(datetime.datetime.now()))
|
|
# generate_valid_contact_list_for_day(segment_number=2)
|
|
# get_old_validated_contact_list()
|
|
# generate_contact_from_mail_list("/Users/lpan/Downloads/邮箱及密码.xlsx")
|
|
# print("end at {}".format(datetime.datetime.now()))
|
|
# generate_all_contact_list()
|
|
# merge_contact_list_files(
|
|
# ["/Users/lpan/Desktop/contact_list_all_old_not_used_contact.xlsx",
|
|
# "/Users/lpan/Desktop/contact_list_2024-06-26.xlsx"])
|
|
# fix_phone_number_format("/Users/lpan/Desktop/15_05_to_test.xlsx")
|