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
@@ -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)