77 lines
3.2 KiB
Python
77 lines
3.2 KiB
Python
import random
|
|
import string
|
|
|
|
import xlsxwriter
|
|
|
|
import params
|
|
from pojo.ReserveResultPojo import ReserveResultPojo
|
|
from pojo.contact_pojo import ContactPojo
|
|
|
|
|
|
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))
|
|
id_number = "57" + str(ran)
|
|
print("The randomly generated string is : 94" + str(ran)) # print the random data
|
|
return id_number
|
|
|
|
|
|
def write_the_valid_profiles_to_excel():
|
|
day_list = ['2022-03-04', '2022-03-07', '2022-03-08', '2022-03-09', '2022-03-10', '2022-03-11', '2022-03-14',
|
|
'2022-03-15', '2022-03-16']
|
|
|
|
collection = []
|
|
for day in day_list:
|
|
collection.extend(params.firebase_store_manager.get_all_successful_items_for_day(day).stream())
|
|
|
|
valid_contacts = []
|
|
# exist_contacts = ExcelHelper().read_contacts()
|
|
for valid_appointment in collection:
|
|
reserve_pojo = ReserveResultPojo.from_firestore_dict(valid_appointment.to_dict())
|
|
# check whether the contact exists already
|
|
exist = [contact for contact in valid_contacts if contact.mail == reserve_pojo.email]
|
|
if len(exist) == 0:
|
|
contact = ContactPojo(reserve_pojo.phone, passport_number=get_random_id_number(),
|
|
last_name=reserve_pojo.lastName, first_name=reserve_pojo.firstName, ccid="",
|
|
mail=reserve_pojo.email, position=0)
|
|
seed = 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=seed))
|
|
contact.mail = "{}_{}{}@163.com".format(contact.first_name, contact.last_name, ran)
|
|
# contact.passport = get_random_id_number()
|
|
# if contact.passport == None or len(contact.passport) == 0:
|
|
# old_contact = [item for item in exist_contacts if item.mail == contact.mail]
|
|
# if len(old_contact) > 0:
|
|
# contact.passport = old_contact[0].passport
|
|
|
|
print(contact)
|
|
valid_contacts.append(contact)
|
|
|
|
row = 0
|
|
col = 0
|
|
# Create a workbook and add a worksheet.
|
|
workbook = xlsxwriter.Workbook('valid_profile.xlsx')
|
|
header_data = ['name', 'phone', 'passport', 'email', 'ccid', 'position']
|
|
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.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)
|
|
worksheet.write(row, col + 4, info.ccid)
|
|
row += 1
|
|
workbook.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# get_random_id_number()
|
|
write_the_valid_profiles_to_excel()
|