add method to extract all validated contacts of the day
This commit is contained in:
@@ -1,13 +1,58 @@
|
||||
import datetime
|
||||
|
||||
import xlsxwriter
|
||||
|
||||
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from src.utils.excel_reader import read_contacts
|
||||
|
||||
|
||||
def upload_contacts_list():
|
||||
_contacts_to_book = read_contacts("/Users/panlei/Desktop/yahoo_aol_valid_25.xlsx")
|
||||
_contacts_to_book = read_contacts("/Users/lpan/Desktop/08_01_24_valid_de.xlsx")
|
||||
return _contacts_to_book
|
||||
|
||||
|
||||
def write_new_contacts_to_excel(valid_contacts: list, day=str(datetime.date.today())):
|
||||
row = 0
|
||||
col = 0
|
||||
# Create a workbook and add a worksheet.
|
||||
workbook = xlsxwriter.Workbook('contact_list_{}.xlsx'.format(day))
|
||||
header_data = ['name', 'phone', 'passport', 'email', 'store', 'ip_country']
|
||||
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:
|
||||
# Iterate over the data and write it out row by row.
|
||||
worksheet.write(row, col, "{} {}".format(info.lastName, info.firstName))
|
||||
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 + 4, info.store)
|
||||
worksheet.write(row, col + 5, info.ip_country)
|
||||
row += 1
|
||||
workbook.close()
|
||||
|
||||
|
||||
def generate_valid_contact_list_for_day():
|
||||
_valid_contact_list = MONGO_STORE_MANAGER.get_all_successful_items_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:
|
||||
for _true_contact in _all_contacts:
|
||||
if _true_contact.mail == _contact.email:
|
||||
_contact.lastName = _true_contact.last_name
|
||||
_contact.firstName = _true_contact.first_name
|
||||
|
||||
if _contact.url_validated:
|
||||
_contact_to_save.append(_contact)
|
||||
write_new_contacts_to_excel(_contact_to_save)
|
||||
|
||||
|
||||
# 把新的联系人存到网上
|
||||
if __name__ == '__main__':
|
||||
contacts_to_book = upload_contacts_list()
|
||||
MONGO_STORE_MANAGER.upload_contact_list(contacts_to_book)
|
||||
# contacts_to_book = upload_contacts_list()
|
||||
# MONGO_STORE_MANAGER.upload_contact_list(contacts_to_book)
|
||||
generate_valid_contact_list_for_day()
|
||||
|
||||
Reference in New Issue
Block a user