add method to get invalid contacts
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
import xlsxwriter
|
||||||
|
|
||||||
|
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
||||||
|
from src.pojo.contact_pojo import ContactPojo
|
||||||
|
|
||||||
|
|
||||||
|
class MailManager:
|
||||||
|
|
||||||
|
def get_invalid_emails_for_day(self):
|
||||||
|
invalid_contacts = []
|
||||||
|
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||||
|
not_validated_items = list(
|
||||||
|
filter(lambda filtered_item: filtered_item.url_validated is None or filtered_item.url_validated is False,
|
||||||
|
successful_items))
|
||||||
|
for item in not_validated_items:
|
||||||
|
if "@gmail" not in item.email and "@163" not in item.email:
|
||||||
|
invalid_contacts.append(
|
||||||
|
ContactPojo(phone_number=item.phone, passport_number=item.passport, last_name=item.lastName,
|
||||||
|
first_name=item.firstName, mail=item.email, ))
|
||||||
|
return invalid_contacts
|
||||||
|
def get_valid_emails_for_day(self):
|
||||||
|
valid_contacts = []
|
||||||
|
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||||
|
validated_items = list(
|
||||||
|
filter(lambda filtered_item: filtered_item.url_validated is not None and filtered_item.url_validated is True,
|
||||||
|
successful_items))
|
||||||
|
for item in validated_items:
|
||||||
|
if "@aol" in item.email:
|
||||||
|
valid_contacts.append(
|
||||||
|
ContactPojo(phone_number=item.phone, passport_number=item.passport, last_name=item.lastName,
|
||||||
|
first_name=item.firstName, mail=item.email, ))
|
||||||
|
return valid_contacts
|
||||||
|
|
||||||
|
def write_invalid_contacts_to_excel(self, contacts: list):
|
||||||
|
row = 0
|
||||||
|
col = 0
|
||||||
|
# Create a workbook and add a worksheet.
|
||||||
|
workbook = xlsxwriter.Workbook('invalid_contacts_{}.xlsx'.format(len(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 contacts:
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
manager = MailManager()
|
||||||
|
manager.write_invalid_contacts_to_excel(manager.get_invalid_emails_for_day())
|
||||||
|
manager.write_invalid_contacts_to_excel(manager.get_valid_emails_for_day())
|
||||||
Reference in New Issue
Block a user