add methode to read all mails
This commit is contained in:
+27
-26
@@ -10,7 +10,7 @@ from src.config import CONTACT_LIST_FILE
|
|||||||
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
||||||
from src.pojo.contact_pojo import ContactPojo
|
from src.pojo.contact_pojo import ContactPojo
|
||||||
from src.pojo.mail.mail_pojo import MailAddress
|
from src.pojo.mail.mail_pojo import MailAddress
|
||||||
from src.utils.generate_random_passport_id import get_random_passport_id_number
|
from src.utils.contacts.generate_random_passport_id import get_random_passport_id_number
|
||||||
|
|
||||||
phone_number_prefix = ['7']
|
phone_number_prefix = ['7']
|
||||||
chinnese_number_prefix = ['13', '15', '18']
|
chinnese_number_prefix = ['13', '15', '18']
|
||||||
@@ -29,6 +29,30 @@ def read_links_to_click(file_path):
|
|||||||
print("error on link " + link)
|
print("error on link " + link)
|
||||||
|
|
||||||
|
|
||||||
|
def read_contacts(file_name=CONTACT_LIST_FILE) -> 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:
|
class ExcelHelper:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -48,31 +72,8 @@ class ExcelHelper:
|
|||||||
user_agent_list.append(user_agent_dict['user_agent'])
|
user_agent_list.append(user_agent_dict['user_agent'])
|
||||||
print(user_agent_list)
|
print(user_agent_list)
|
||||||
|
|
||||||
def read_contacts(self, file_name=CONTACT_LIST_FILE) -> 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
|
|
||||||
|
|
||||||
def check_contact_list(self, file_name=CONTACT_LIST_FILE):
|
def check_contact_list(self, file_name=CONTACT_LIST_FILE):
|
||||||
contact_list = self.read_contacts(file_name)
|
contact_list = read_contacts(file_name)
|
||||||
for contact in contact_list:
|
for contact in contact_list:
|
||||||
if contact.first_name is None or len(contact.first_name) == 0:
|
if contact.first_name is None or len(contact.first_name) == 0:
|
||||||
print("error in firstName for " + contact.mail)
|
print("error in firstName for " + contact.mail)
|
||||||
@@ -238,7 +239,7 @@ def write_destinaire_email(valid_contacts: list, generate_passport=True):
|
|||||||
|
|
||||||
def save_mails_to_db():
|
def save_mails_to_db():
|
||||||
excel_reader = ExcelHelper()
|
excel_reader = ExcelHelper()
|
||||||
emails = excel_reader.read_email_pojo("/Users/panlei/Downloads/邮箱及密码.xlsx")
|
emails = excel_reader.read_email_pojo("/Users/lpan/Downloads/邮箱及密码.xlsx")
|
||||||
print(emails)
|
print(emails)
|
||||||
for mail in emails:
|
for mail in emails:
|
||||||
MONGO_STORE_MANAGER.save_destinary_emails(mail)
|
MONGO_STORE_MANAGER.save_destinary_emails(mail)
|
||||||
|
|||||||
Reference in New Issue
Block a user