128 lines
4.9 KiB
Python
Executable File
128 lines
4.9 KiB
Python
Executable File
import json
|
|
import random
|
|
import string
|
|
|
|
import pandas as pandas
|
|
|
|
from models.contact_pojo import ContactPojo
|
|
|
|
phone_number_prefix = ['7']
|
|
chinnese_number_prefix = ['13', '15', '18']
|
|
|
|
|
|
def read_contacts(file_name) -> list:
|
|
print("read file " + file_name)
|
|
contact_list_in_json = pandas.read_excel(file_name).to_json(orient='records')
|
|
contact_dict_list = json.loads(contact_list_in_json)
|
|
contact_list = []
|
|
for contact_dict in contact_dict_list:
|
|
if contact_dict['name']:
|
|
raw_name = contact_dict['name'].strip()
|
|
name = raw_name.split(' ')
|
|
last_name = name[0]
|
|
if len(name) == 2:
|
|
first_name = name[-1]
|
|
else:
|
|
first_name = ''.join(name[1:len(name)])
|
|
|
|
contact = ContactPojo(phone_number=contact_dict['phone'],
|
|
last_name=last_name,
|
|
first_name=first_name,
|
|
passport_number=contact_dict['passport'],
|
|
mail=contact_dict['email'])
|
|
contact_list.append(contact)
|
|
return contact_list
|
|
|
|
|
|
class ExcelHelper:
|
|
|
|
def __init__(self):
|
|
self._df = pandas.Series()
|
|
|
|
def check_contact_list(self, file_name):
|
|
contact_list = read_contacts(file_name)
|
|
for contact in contact_list:
|
|
if contact.first_name is None or len(contact.first_name) == 0:
|
|
print("error in firstName for " + contact.mail)
|
|
if contact.last_name is None or len(contact.last_name) == 0:
|
|
print("error in last_name for " + contact.mail)
|
|
if contact.phone is None or len(contact.phone) == 0:
|
|
print("error in phone for " + contact.mail)
|
|
if contact.passport is None or len(contact.passport) == 0:
|
|
print("error in passport_number for " + contact.mail)
|
|
if contact.mail is None or len(contact.mail) == 0:
|
|
print("error in mail for " + contact.phone_number)
|
|
|
|
|
|
def read_names(self, file_name) -> list:
|
|
contact_list_in_json = pandas.read_excel(file_name).to_json(orient='records')
|
|
contact_dict_list = json.loads(contact_list_in_json)
|
|
contact_list = []
|
|
count = 2
|
|
for contact_dict in contact_dict_list:
|
|
if contact_dict['name']:
|
|
raw_name = contact_dict['name'].strip()
|
|
name = raw_name.split(' ')
|
|
if len(name) == 1:
|
|
name = raw_name.split('\xa0')
|
|
if len(name) == 1:
|
|
print("error in " + str(name))
|
|
last_name = name[0]
|
|
if len(name) == 2:
|
|
first_name = name[-1]
|
|
else:
|
|
first_name = ''.join(name[1:len(name)])
|
|
|
|
contact = ContactPojo(phone_number="",
|
|
last_name=last_name,
|
|
first_name=first_name,
|
|
passport_number="",
|
|
mail="")
|
|
|
|
if len(first_name) == 0:
|
|
print("first_name is empty: position:" + str(count))
|
|
print(name)
|
|
if len(last_name) == 0:
|
|
print("last_name is empty: position:" + str(count))
|
|
count = count + 1
|
|
contact_list.append(contact)
|
|
|
|
return contact_list
|
|
|
|
|
|
def get_random_fr_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)
|
|
return id_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)
|
|
prefix = random.choice(chinnese_number_prefix)
|
|
return prefix + id_number
|
|
|
|
|
|
def generate_email_from_name(first_name: str, last_name: str) -> str:
|
|
length = 2 # number of characters in the string.
|
|
ran = ''.join(random.choices(string.digits, k=length))
|
|
separator = ['.', '_', '']
|
|
domains = ['gmail.com', 'hotmail.com', 'yahoo.com', 'aol.com', 'outlook.com', 'hotmail.fr', 'gmx.com',
|
|
'hotmail.com', 'yahoo.com', 'aol.com', 'hotmail.com']
|
|
email = "{}{}{}{}@{}".format(last_name.lower(), random.choice(separator),
|
|
first_name.replace("-", "").replace("'", "").lower(), ran,
|
|
random.choice(domains))
|
|
print(email)
|
|
return email
|
|
|
|
|
|
def get_random_id_number() -> str:
|
|
# write_the_valid_profiles_to_excel()
|
|
S = 8 # number of characters in the string.
|
|
# call random.choices() string module to find the string in Uppercase + numeric data.
|
|
ran = ''.join(random.choices(string.digits, k=S))
|
|
print("The randomly generated string is : 94" + str(ran)) # print the random data
|
|
return ran
|