add method to fix phone number error
This commit is contained in:
@@ -3,19 +3,29 @@ import datetime
|
||||
import xlsxwriter
|
||||
|
||||
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from src.utils.excel_reader import read_contacts
|
||||
from src.utils.excel_reader import read_contacts, fr_phone_number_prefix, get_random_fr_phone_numbers
|
||||
|
||||
|
||||
def upload_contacts_list():
|
||||
_contacts_to_book = read_contacts("/Users/lpan/Desktop/contacts_valid_2.xlsx")
|
||||
_contacts_to_book = read_contacts("/Users/lpan/Desktop/contact_list_2024-02-12.xlsx")
|
||||
return _contacts_to_book
|
||||
|
||||
|
||||
def write_new_contacts_to_excel(valid_contacts: list, day=str(datetime.date.today())):
|
||||
def fix_phone_number_format(file_path):
|
||||
_contact_list = read_contacts(file_path)
|
||||
for _contact in _contact_list:
|
||||
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="yahoo_aol_valid_26-1")
|
||||
|
||||
|
||||
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(day))
|
||||
workbook = xlsxwriter.Workbook('contact_list_{}.xlsx'.format(file_name))
|
||||
header_data = ['name', 'phone', 'passport', 'email', 'store', 'ip_country']
|
||||
worksheet = workbook.add_worksheet()
|
||||
header_format = workbook.add_format({'bold': True})
|
||||
@@ -25,10 +35,10 @@ def write_new_contacts_to_excel(valid_contacts: list, day=str(datetime.date.toda
|
||||
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.lastName, info.firstName))
|
||||
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.email)
|
||||
worksheet.write(row, col + 3, info.mail)
|
||||
worksheet.write(row, col + 4, info.store)
|
||||
worksheet.write(row, col + 5, info.ip_country)
|
||||
row += 1
|
||||
@@ -40,21 +50,28 @@ def generate_valid_contact_list_for_day():
|
||||
_all_contacts = MONGO_STORE_MANAGER.get_all_contacts_to_book()
|
||||
_contact_to_save = []
|
||||
for _contact in _valid_contact_list:
|
||||
if _contact.lastName is None or len(_contact.lastName) == 0:
|
||||
if _contact.last_name is None or len(_contact.last_name) == 0:
|
||||
for _true_contact in _all_contacts:
|
||||
if _true_contact.mail == _contact.email:
|
||||
_contact.lastName = _true_contact.last_name
|
||||
if _true_contact.mail == _contact.mail:
|
||||
_contact.last_name = _true_contact.last_name
|
||||
_contact.phone = _true_contact.phone
|
||||
_contact.passport = _true_contact.passport
|
||||
_contact.firstName = _true_contact.first_name
|
||||
_contact.first_name = _true_contact.first_name
|
||||
|
||||
if _contact.url_validated:
|
||||
_contact_to_save.append(_contact)
|
||||
write_new_contacts_to_excel(_contact_to_save)
|
||||
|
||||
|
||||
def generate_all_contact_list():
|
||||
_all_contacts = MONGO_STORE_MANAGER.get_all_contacts_to_book()
|
||||
write_new_contacts_to_excel(_all_contacts, file_name="all")
|
||||
|
||||
|
||||
# 把新的联系人存到网上
|
||||
if __name__ == '__main__':
|
||||
# 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/lpan/Desktop/yahoo_aol_valid_26-1.xlsx")
|
||||
|
||||
Reference in New Issue
Block a user