add method to generate list to register
This commit is contained in:
+13
-1
@@ -7,6 +7,7 @@ from pymongo import MongoClient
|
|||||||
from src.pojo.ReserveResultPojo import ReserveResultPojo
|
from src.pojo.ReserveResultPojo import ReserveResultPojo
|
||||||
from src.pojo.ResultEnum import ResultEnum
|
from src.pojo.ResultEnum import ResultEnum
|
||||||
from src.pojo.accepted_appointment_pojo import AcceptedAppointmentPojo
|
from src.pojo.accepted_appointment_pojo import AcceptedAppointmentPojo
|
||||||
|
from src.pojo.address_info_pojo import AddressInfoPojo
|
||||||
from src.pojo.black_contact import BlackContactPojo
|
from src.pojo.black_contact import BlackContactPojo
|
||||||
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
|
||||||
@@ -21,6 +22,7 @@ EMAIL_LIST = "EMAIL_LIST"
|
|||||||
DESTINATION_EMAIL_LIST = "DESTINATION_EMAIL_LIST"
|
DESTINATION_EMAIL_LIST = "DESTINATION_EMAIL_LIST"
|
||||||
LINKS_TO_VALIDATE = "LINKS_TO_VALIDATE"
|
LINKS_TO_VALIDATE = "LINKS_TO_VALIDATE"
|
||||||
INVALID_EMAIL_LIST = "INVALID_EMAIL_LIST"
|
INVALID_EMAIL_LIST = "INVALID_EMAIL_LIST"
|
||||||
|
ADRESSE_LIST ="address"
|
||||||
|
|
||||||
|
|
||||||
class MongoDbManager:
|
class MongoDbManager:
|
||||||
@@ -94,6 +96,16 @@ class MongoDbManager:
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
self.logger.info(error)
|
self.logger.info(error)
|
||||||
return appointment_list_contacts
|
return appointment_list_contacts
|
||||||
|
def get_all_address_list(self) -> list:
|
||||||
|
collection_name = ADRESSE_LIST
|
||||||
|
_address_list = []
|
||||||
|
try:
|
||||||
|
collection_to_use = self.db[collection_name]
|
||||||
|
for document in collection_to_use.find():
|
||||||
|
_address_list.append(AddressInfoPojo.from_firestore_dict(document))
|
||||||
|
except Exception as error:
|
||||||
|
self.logger.info(error)
|
||||||
|
return _address_list
|
||||||
|
|
||||||
def get_all_accepted_appointments_for_day(self, day) -> list:
|
def get_all_accepted_appointments_for_day(self, day) -> list:
|
||||||
collection_name = ACCEPTED_APPOINTMENT_LIST
|
collection_name = ACCEPTED_APPOINTMENT_LIST
|
||||||
@@ -322,7 +334,7 @@ MONGO_STORE_MANAGER = MongoDbManager()
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
db_manager = MongoDbManager()
|
db_manager = MongoDbManager()
|
||||||
for c in db_manager.get_all_contacts_to_book():
|
for c in db_manager.get_all_address_list():
|
||||||
print(c)
|
print(c)
|
||||||
# print(db_manager.get_code_for_email("singleton_teri1991@aol.com"))
|
# print(db_manager.get_code_for_email("singleton_teri1991@aol.com"))
|
||||||
# black_list = db_manager.get_blacklist_contacts()
|
# black_list = db_manager.get_blacklist_contacts()
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
class AddressInfoPojo:
|
||||||
|
|
||||||
|
def __init__(self, address, city, zip_code):
|
||||||
|
self.address = address
|
||||||
|
self.city = city
|
||||||
|
self.zip_code = zip_code
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "address:{}, city:{}, zip_code:{}".format(self.address, self.city, self.zip_code)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_firestore_dict(source):
|
||||||
|
address = source['address']
|
||||||
|
city = source['city']
|
||||||
|
zip_code = source['zip_code']
|
||||||
|
result = AddressInfoPojo(address=address, city=city, zip_code=zip_code)
|
||||||
|
return result
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import datetime
|
||||||
|
import random
|
||||||
|
|
||||||
|
import xlsxwriter
|
||||||
|
|
||||||
|
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
||||||
|
|
||||||
|
|
||||||
|
def generate_list_to_register():
|
||||||
|
_valid_contact_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||||
|
_already_registered_list = MONGO_STORE_MANAGER.get_all_registered_users()
|
||||||
|
_contact_list_to_register = []
|
||||||
|
for _contact in _valid_contact_list:
|
||||||
|
_to_add = True
|
||||||
|
for _registered_user in _already_registered_list:
|
||||||
|
if _contact.mail == _registered_user.mail:
|
||||||
|
_to_add = False
|
||||||
|
break
|
||||||
|
if _to_add:
|
||||||
|
_contact_list_to_register.append(_contact)
|
||||||
|
return _contact_list_to_register
|
||||||
|
|
||||||
|
|
||||||
|
def write_new_contacts_to_register_to_excel(valid_contacts: list, file_name=str(datetime.date.today())):
|
||||||
|
_address_list = MONGO_STORE_MANAGER.get_all_address_list()
|
||||||
|
row = 0
|
||||||
|
col = 0
|
||||||
|
# Create a workbook and add a worksheet.
|
||||||
|
workbook = xlsxwriter.Workbook('to_register_list_{}.xlsx'.format(file_name))
|
||||||
|
header_data = ['firstName', 'lastName', 'password', 'email', 'phone', 'address', 'city', 'zipCode']
|
||||||
|
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
|
||||||
|
_choosed_address = random.choice(_address_list)
|
||||||
|
for info in valid_contacts:
|
||||||
|
_password = "Rdv@{}".format(random.randint(20222021, 20222300))
|
||||||
|
# Iterate over the data and write it out row by row.
|
||||||
|
worksheet.write(row, col, info.first_name)
|
||||||
|
worksheet.write(row, col + 1, info.last_name)
|
||||||
|
worksheet.write(row, col + 2, _password)
|
||||||
|
worksheet.write(row, col + 3, info.mail)
|
||||||
|
worksheet.write(row, col + 4, info.phone)
|
||||||
|
worksheet.write(row, col + 5, _choosed_address.address)
|
||||||
|
worksheet.write(row, col + 6, _choosed_address.city)
|
||||||
|
worksheet.write(row, col + 7, _choosed_address.zip_code)
|
||||||
|
row += 1
|
||||||
|
workbook.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
write_new_contacts_to_register_to_excel(generate_list_to_register())
|
||||||
Reference in New Issue
Block a user