add method to fix phone number error

This commit is contained in:
2024-02-18 23:09:19 +01:00
parent 760fbe4a97
commit 9553d5e3c0
4 changed files with 46 additions and 60 deletions
+27 -10
View File
@@ -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")
+8 -4
View File
@@ -10,17 +10,17 @@ class ContactPojo:
last_name: str
first_name: str
mail: str
note: str
store: str
ip_country: str
def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, mail: str,
def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, mail: str, store: str,
ip_country="FR"):
self.phone = str(phone_number).replace(".0", "")
self.passport = passport_number
self.last_name = last_name
self.first_name = first_name
self.mail = mail
self.note = ""
self.store = store
self.ip_country = ip_country
def to_firestore_dict(self):
@@ -30,6 +30,7 @@ class ContactPojo:
u'last_name': self.last_name,
u'first_name': self.first_name,
u'mail': self.mail,
u'store': self.store,
u'ip_country': self.ip_country
}
return dest
@@ -47,10 +48,13 @@ class ContactPojo:
email = source['mail']
last_name = source['last_name']
first_name = source['first_name']
store = "random"
if 'store' in source:
store = source['store']
ip_country = "FR"
if source.get('ip_country'):
ip_country = source['ip_country']
result = ContactPojo(phone_number=phone, passport_number=passport, mail=email,
last_name=last_name, first_name=first_name)
last_name=last_name, first_name=first_name, store=store)
result.ip_country = ip_country
return result
@@ -33,19 +33,6 @@ def get_random_number(size=6) -> str:
return ran
def get_captcha_error_contact_from_contact(contact: ContactPojo, error_type: int) -> ContactInErrorPojo:
captcha_error = ContactInErrorPojo()
captcha_error.mail = contact.mail
captcha_error.ccid = contact.ccid
captcha_error.phone = contact.phone
captcha_error.passport = contact.passport
captcha_error.first_name = contact.first_name
captcha_error.last_name = contact.last_name
captcha_error.position = contact.position
captcha_error.error_type = error_type
return captcha_error
def generate_titre_sejour_number(size=10) -> list:
number_list = []
for i in range(0, size):
+11 -33
View File
@@ -11,7 +11,7 @@ from src.pojo.contact_pojo import ContactPojo
from src.pojo.mail.mail_pojo import MailAddress
from src.utils.contacts.generate_random_passport_id import get_random_passport_id_number
phone_number_prefix = ['7']
fr_phone_number_prefix = ['73', '74', '75', '76', '77', '78', '79']
chinnese_number_prefix = ['13', '15', '18']
@@ -45,12 +45,15 @@ def read_contacts(file_name) -> list:
ip_country = "FR"
if contact_dict.get('ip_country') is not None:
ip_country = contact_dict['ip_country']
store = "random"
if contact_dict.get('store') is not None:
store = contact_dict['store']
contact = ContactPojo(phone_number=contact_dict['phone'],
last_name=last_name,
first_name=first_name,
passport_number=contact_dict['passport'],
mail=contact_dict['email'])
mail=contact_dict['email'], store=store)
contact.ip_country = ip_country
contact_list.append(contact)
return contact_list
@@ -154,18 +157,18 @@ class ExcelHelper:
def get_random_fr_phone_numbers():
length = 8 # number of characters in the string.
length = 7 # number of characters in the string.
ran = ''.join(random.choices(string.digits, k=length))
id_number = random.choice(phone_number_prefix) + str(ran)
return id_number
_phone_number = random.choice(fr_phone_number_prefix) + str(ran)
return _phone_number
def get_random_cn_phone_numbers():
length = 8 # number of characters in the string.
ran = ''.join(random.choices(string.digits, k=length))
id_number = random.choice(phone_number_prefix) + str(ran)
_phone_number = random.choice(fr_phone_number_prefix) + str(ran)
prefix = random.choice(chinnese_number_prefix)
return prefix + id_number
return prefix + _phone_number
def generate_email_from_name(first_name: str, last_name: str) -> str:
@@ -190,31 +193,6 @@ def get_random_id_number() -> str:
return ran
def write_new_contacts_to_excel(valid_contacts: list, generate_passport=True):
row = 0
col = 0
# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('real_contacts_{}.xlsx'.format(len(valid_contacts)))
header_data = ['name', 'phone', 'passport', 'email']
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:
info.phone = get_random_fr_phone_numbers()
info.passport = get_random_passport_id_number()
info.mail = generate_email_from_name(info.first_name, info.last_name)
# 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)
row += 1
workbook.close()
def write_destinaire_email(valid_contacts: list, generate_passport=True):
row = 0
col = 0
@@ -242,7 +220,7 @@ def write_destinaire_email(valid_contacts: list, generate_passport=True):
def save_mails_to_db():
excel_reader = ExcelHelper()
emails = excel_reader.read_email_pojo("/Users/lpan/Downloads/邮箱及密码.xlsx")
emails = excel_reader.read_email_pojo("~/Downloads/邮箱及密码.xlsx")
print(emails)
for mail in emails:
MONGO_STORE_MANAGER.save_destinary_emails(mail)