Merge branch 'master' into feature/automatic

This commit is contained in:
Lei PAN
2022-06-04 17:46:15 +02:00
6 changed files with 125 additions and 24 deletions
+1
View File
@@ -14,3 +14,4 @@ appointment_*.log
./build
./dist
./contact_all.xlsx
./utils/new_profile_500.xlsx
+2 -1
View File
@@ -16,7 +16,7 @@ SORRY_SENTENCE_EN = "we are extremely sorry that we were not able to fulfill"
NOT_AVAILABLE_CONTENT = "For more than 130 years, our House has offered its full expertise to satisfy"
PENDING_SENTENCE = "Ce soir, entre 20:00 et 20:30, vous obtiendrez une réponse par e-mail."
PENDING_SENTENCE_EN = "This evening between 20:00 and 20:30 you will receive a response by email."
BLANK_URL = "about:blank"
class TlsPlaywright(threading.local):
def __init__(self) -> None:
@@ -116,6 +116,7 @@ if __name__ == '__main__':
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
result_list.append(reserve_pojo)
with ThreadPoolExecutor(max_workers=25) as executor:
for reserve in result_list:
count = count + 1
+96
View File
@@ -1,9 +1,15 @@
import json
import random
import string
import pandas as pandas
import xlsxwriter
from definitions import CONTACT_LIST_FILE
from pojo.contact_pojo import ContactPojo
phone_number_prefix = ['6', '7']
class ExcelHelper:
@@ -36,3 +42,93 @@ class ExcelHelper:
mail=contact_dict['email'])
contact_list.append(contact)
return contact_list
def read_names(self, file_name=CONTACT_LIST_FILE) -> list:
contact_list_in_json = pandas.read_excel(file_name).to_json(orient='records')
contact_dict_list = json.loads(contact_list_in_json)
contact_list = []
count = 2
for contact_dict in contact_dict_list:
if contact_dict['name']:
raw_name = contact_dict['name'].strip()
name = raw_name.split(' ')
if len(name) == 1:
name = raw_name.split('\xa0')
last_name = name[0]
if len(name) == 2:
first_name = name[-1]
else:
first_name = ''.join(name[1:len(name)])
contact = ContactPojo(phone_number="",
last_name=last_name,
first_name=first_name,
passport_number="",
mail="")
if len(first_name) == 0:
print("first_name is empty: position:" + str(count))
print(name)
if len(last_name) == 0:
print("last_name is empty: position:" + str(count))
count = count + 1
contact_list.append(contact)
return contact_list
def get_random_phone_numbers():
length = 8 # number of characters in the string.
ran = ''.join(random.choices(string.digits, k=length))
id_number = random.choice(phone_number_prefix) + str(ran)
return id_number
def generate_email_from_name(first_name: str, last_name: str) -> str:
length = 4 # number of characters in the string.
ran = ''.join(random.choices(string.digits, k=length))
separator = ['.', '_', '']
email = "{}{}{}{}@163.com".format(last_name.lower(), random.choice(separator), first_name.lower(), ran)
print(email)
return email
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))
print("The randomly generated string is : 94" + str(ran)) # print the random data
return ran
def write_new_contacts_to_excel(valid_contacts: list):
row = 0
col = 0
# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('new_profile_{}.xlsx'.format(len(valid_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 valid_contacts:
info.phone = get_random_phone_numbers()
info.passport = get_random_id_number()
info.mail = generate_email_from_name(info.first_name, info.last_name)
# 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__':
excel_reader = ExcelHelper()
contacts = excel_reader.read_names("C:/Users/landd/Desktop/1000.xlsx")
print(contacts)
write_new_contacts_to_excel(valid_contacts=contacts)
+4 -4
View File
@@ -19,19 +19,19 @@ def get_random_id_number() -> str:
def write_the_valid_profiles_to_excel():
day_list = ['2022-03-23','2022-03-24','2022-03-25']
day_list = ['2022-05-30']
collection = []
for day in day_list:
collection.extend(params.firebase_store_manager.get_all_successful_items_for_day(day).stream())
collection.extend(params.firebase_store_manager.get_all_successful_items_for_day(day, source_from=None).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:
# 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)
-1
View File
@@ -9,7 +9,6 @@ def get_random_id_number() -> str:
S = 8 # number of characters in the string.
ran = ''.join(random.choices(string.digits, k=S))
id_number = str(ran)
# print("The randomly generated string is : 94" + str(ran)) # print the random data
return id_number
+9 -5
View File
@@ -26,9 +26,13 @@ OTP_FIELD_ID = "#sms_code"
MESSAGE_FIELD_CLASS = ".message"
CONFIRMED_MESSAGE = "Your request for a Leather Goods appointment has been registered"
CONFIRMED_MESSAGE_FR = "Votre demande de rendez-vous Maroquinerie a bien été enregistrée et nous vous en remercions."
DOUBLE_REQUEST_ERROR_MESSAGE = "A request with the same data has already been validated today."
DOUBLE_REQUEST_ERROR_MESSAGE_FR = "Une demande avec les données saisies a déjà été validée aujourdhui."
TOO_MANY_REQUEST_ERROR_MESSAGE = "Due to a large number of requests"
TOO_MANY_REQUEST_ERROR_MESSAGE_FR = "Suite à un trop grand nombre de demandes aujourdhui,"
CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué"
TIME_OUT = 400000
OTP_TIMEOUT = 240
PAGE_TIMEOUT = 40000
@@ -114,7 +118,7 @@ class CommandorPage:
otp_sent.wait_for(state='visible', timeout=TIME_OUT)
time.sleep(get_random_wait_time())
message = self.page.content()
if CONFIRMED_MESSAGE in message:
if CONFIRMED_MESSAGE in message or CONFIRMED_MESSAGE_FR in message:
# publish the successful message
self.logger.info("url is " + self.page.url)
self.publish_message_to_queue(self.contact, PublishType.SUCCESS, self.page.url)
@@ -181,7 +185,7 @@ class CommandorPage:
self.fill_fields()
try:
message = self.page.content()
if CONFIRMED_MESSAGE in message:
if CONFIRMED_MESSAGE in message or CONFIRMED_MESSAGE_FR in message:
# publish the successful message
self.publish_message_to_queue(self.contact, PublishType.SUCCESS, self.page.url)
self.get_errors()
@@ -242,19 +246,19 @@ class CommandorPage:
self.logger.error(ext)
def _handle_errors(self, erro_content: str):
if DOUBLE_REQUEST_ERROR_MESSAGE in erro_content:
if DOUBLE_REQUEST_ERROR_MESSAGE in erro_content or DOUBLE_REQUEST_ERROR_MESSAGE_FR in erro_content:
# this email has been already used
if not self.is_finished:
params.oracle_log_sender.send_double_data_error(self.contact)
self.is_finished = True
self.termine()
elif TOO_MANY_REQUEST_ERROR_MESSAGE in erro_content:
elif TOO_MANY_REQUEST_ERROR_MESSAGE in erro_content or TOO_MANY_REQUEST_ERROR_MESSAGE_FR in erro_content:
# this email has been already used
if not self.is_finished:
params.oracle_log_sender.send_too_many_error(self.contact)
self.is_finished = True
self.termine()
elif CAPTCHA_ERROR_MESSAGE in erro_content:
elif CAPTCHA_ERROR_MESSAGE in erro_content or CAPTCHA_ERROR_MESSAGE_FR in erro_content:
# this email has been already used
self.is_captcha_in_error = True
if not self.is_finished: