added verification de URL not valide

This commit is contained in:
2022-07-29 22:30:49 +02:00
parent 01cf4211fc
commit f890454e25
5 changed files with 73 additions and 6 deletions
+7 -3
View File
@@ -23,6 +23,7 @@ SORRY_SENTENCE_FR = "nous sommes sincèrement désolés de n'avoir pu vous satis
SORRY_SENTENCE_EN = "we are extremely sorry that we were not able to fulfill" 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" 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 = "Ce soir, entre 20:00 et 20:30, vous obtiendrez une réponse par e-mail."
URL_TO_VALID_SENTENCE = "Nous avons envoyé un lien par e-mail."
PENDING_SENTENCE_EN = "This evening between 20:00 and 20:30 you will receive a response by email." PENDING_SENTENCE_EN = "This evening between 20:00 and 20:30 you will receive a response by email."
# URLs to ignore during checking results # URLs to ignore during checking results
BLANK_URL = "about:blank" BLANK_URL = "about:blank"
@@ -80,6 +81,9 @@ class ResultChecker:
elif PENDING_SENTENCE in content: elif PENDING_SENTENCE in content:
print("status is PENDING") print("status is PENDING")
status = ResultEnum.PENDING status = ResultEnum.PENDING
elif URL_TO_VALID_SENTENCE in content:
print("status is REFUSED")
status = ResultEnum.REFUSED
elif PENDING_SENTENCE_EN in content: elif PENDING_SENTENCE_EN in content:
print("status is PENDING") print("status is PENDING")
status = ResultEnum.PENDING status = ResultEnum.PENDING
@@ -108,10 +112,10 @@ def check_results(headless=False):
reserve_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day() reserve_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
print("size is " + str(len(reserve_list))) print("size is " + str(len(reserve_list)))
start_check(reserve_list, firestore_collection, headless, need_send_email=False) start_check(reserve_list, firestore_collection, headless, need_send_email=False)
reserve_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day() # reserve_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
start_check(reserve_list, firestore_collection, headless, need_send_email=True) # start_check(reserve_list, firestore_collection, headless, need_send_email=True)
# copy the accepted info to the accepted collection # copy the accepted info to the accepted collection
migre_accepted_appointment(str(datetime.date.today())) # migre_accepted_appointment(str(datetime.date.today()))
def start_check(reserve_list, firestore_collection, headless: bool, need_send_email: bool): def start_check(reserve_list, firestore_collection, headless: bool, need_send_email: bool):
+10
View File
@@ -9,11 +9,13 @@ 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.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_pojo import Mail
MONGO_DB_URL = "mongo.lpaconsulting.fr" MONGO_DB_URL = "mongo.lpaconsulting.fr"
CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_" CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_"
BLACK_LIST = "BLACK_LIST" BLACK_LIST = "BLACK_LIST"
ACCEPTED_APPOINTMENT_LIST = "ACCEPTED_APPOINTMENT_LIST" ACCEPTED_APPOINTMENT_LIST = "ACCEPTED_APPOINTMENT_LIST"
EMAIL_LIST = "EMAIL_LIST"
class MongoDbManager: class MongoDbManager:
@@ -34,6 +36,14 @@ class MongoDbManager:
except Exception as Error: except Exception as Error:
self.logger.info(Error) self.logger.info(Error)
def insert_email(self, reserve: Mail):
try:
collection_to_use = self.db[EMAIL_LIST]
collection_to_use.replace_one(filter={'_id': reserve.mail, }, replacement=reserve.to_firestore_dict(),
upsert=True)
except Exception as Error:
self.logger.info(Error)
def insert_accepted_reserve(self, accepted_pojo: AcceptedAppointmentPojo): def insert_accepted_reserve(self, accepted_pojo: AcceptedAppointmentPojo):
try: try:
collection_to_use = self.db[ACCEPTED_APPOINTMENT_LIST] collection_to_use = self.db[ACCEPTED_APPOINTMENT_LIST]
+14
View File
@@ -0,0 +1,14 @@
class Mail:
def __init__(self, mail, password):
self.mail = mail
self.password = password
def __repr__(self):
return "邮箱:{}, 密码:{}".format(self.mail, self.password)
def to_firestore_dict(self):
dest = {
u'mail': self.mail,
u'password': self.password
}
return dest
+21 -3
View File
@@ -6,7 +6,9 @@ import pandas as pandas
import xlsxwriter import xlsxwriter
from src.config import CONTACT_LIST_FILE from src.config import CONTACT_LIST_FILE
from src.db.mongo_manager import MONGO_STORE_MANAGER
from src.pojo.contact_pojo import ContactPojo from src.pojo.contact_pojo import ContactPojo
from src.pojo.mail_pojo import Mail
from src.utils.generate_random_passport_id import get_random_passport_id_number from src.utils.generate_random_passport_id import get_random_passport_id_number
phone_number_prefix = ['6'] phone_number_prefix = ['6']
@@ -44,6 +46,19 @@ class ExcelHelper:
contact_list.append(contact) contact_list.append(contact)
return contact_list return contact_list
def read_mails_and_pwd(self,
file_name='/Users/lpan/Desktop/163.xlsx'):
contact_list = []
mail_list_in_json = pandas.read_excel(file_name).to_json(orient='records')
contact_dict_list = json.loads(mail_list_in_json)
for contact_dict in contact_dict_list:
if contact_dict['mail']:
mail = contact_dict['mail'].strip()
pwd = contact_dict['password']
contact = Mail(mail, pwd)
contact_list.append(contact)
return contact_list
def read_names(self, file_name=CONTACT_LIST_FILE) -> 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_list_in_json = pandas.read_excel(file_name).to_json(orient='records')
contact_dict_list = json.loads(contact_list_in_json) contact_dict_list = json.loads(contact_list_in_json)
@@ -136,6 +151,9 @@ def write_new_contacts_to_excel(valid_contacts: list):
if __name__ == '__main__': if __name__ == '__main__':
excel_reader = ExcelHelper() excel_reader = ExcelHelper()
contacts = excel_reader.read_names("/Users/lpan/Downloads/real_contacts.xlsx") # contacts = excel_reader.read_names("/Users/lpan/Downloads/real_contacts.xlsx")
print(contacts) # print(contacts)
write_new_contacts_to_excel(valid_contacts=contacts) # write_new_contacts_to_excel(valid_contacts=contacts)
for mail in excel_reader.read_mails_and_pwd():
MONGO_STORE_MANAGER.insert_email(mail)
+21
View File
@@ -0,0 +1,21 @@
from src.db.mongo_manager import MONGO_STORE_MANAGER
from src.utils.excel_reader import ExcelHelper
mail_list = ExcelHelper().read_mails_and_pwd()
def get_mail_list() -> list:
mail_list = []
resever_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
for reserve in resever_list:
mail_list.append(reserve.email)
return mail_list
def find_password_for_email(email:str) -> str:
for mail_pojo in mail_list:
if mail_pojo.mail == email:
print(mail_pojo)
if __name__ == '__main__':
mails = get_mail_list()
print(len(mails))
for mail in mails:
find_password_for_email(mail)