diff --git a/src/check_results.py b/src/check_results.py index c23423d..0bfed53 100644 --- a/src/check_results.py +++ b/src/check_results.py @@ -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" 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." +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." # URLs to ignore during checking results BLANK_URL = "about:blank" @@ -80,6 +81,9 @@ class ResultChecker: elif PENDING_SENTENCE in content: print("status is PENDING") status = ResultEnum.PENDING + elif URL_TO_VALID_SENTENCE in content: + print("status is REFUSED") + status = ResultEnum.REFUSED elif PENDING_SENTENCE_EN in content: print("status is PENDING") status = ResultEnum.PENDING @@ -108,10 +112,10 @@ def check_results(headless=False): reserve_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day() print("size is " + str(len(reserve_list))) start_check(reserve_list, firestore_collection, headless, need_send_email=False) - reserve_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day() - start_check(reserve_list, firestore_collection, headless, need_send_email=True) + # reserve_list = MONGO_STORE_MANAGER.get_all_successful_items_for_day() + # start_check(reserve_list, firestore_collection, headless, need_send_email=True) # 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): diff --git a/src/db/mongo_manager.py b/src/db/mongo_manager.py index aa95578..903542e 100644 --- a/src/db/mongo_manager.py +++ b/src/db/mongo_manager.py @@ -9,11 +9,13 @@ from src.pojo.ResultEnum import ResultEnum from src.pojo.accepted_appointment_pojo import AcceptedAppointmentPojo from src.pojo.black_contact import BlackContactPojo from src.pojo.contact_pojo import ContactPojo +from src.pojo.mail_pojo import Mail MONGO_DB_URL = "mongo.lpaconsulting.fr" CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_" BLACK_LIST = "BLACK_LIST" ACCEPTED_APPOINTMENT_LIST = "ACCEPTED_APPOINTMENT_LIST" +EMAIL_LIST = "EMAIL_LIST" class MongoDbManager: @@ -34,6 +36,14 @@ class MongoDbManager: except Exception as 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): try: collection_to_use = self.db[ACCEPTED_APPOINTMENT_LIST] diff --git a/src/pojo/mail_pojo.py b/src/pojo/mail_pojo.py new file mode 100644 index 0000000..7e12524 --- /dev/null +++ b/src/pojo/mail_pojo.py @@ -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 diff --git a/src/utils/excel_reader.py b/src/utils/excel_reader.py index 1fd38b8..edbe05a 100644 --- a/src/utils/excel_reader.py +++ b/src/utils/excel_reader.py @@ -6,7 +6,9 @@ import pandas as pandas import xlsxwriter 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.mail_pojo import Mail from src.utils.generate_random_passport_id import get_random_passport_id_number phone_number_prefix = ['6'] @@ -44,6 +46,19 @@ class ExcelHelper: contact_list.append(contact) 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: contact_list_in_json = pandas.read_excel(file_name).to_json(orient='records') 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__': excel_reader = ExcelHelper() - contacts = excel_reader.read_names("/Users/lpan/Downloads/real_contacts.xlsx") - print(contacts) - write_new_contacts_to_excel(valid_contacts=contacts) + # contacts = excel_reader.read_names("/Users/lpan/Downloads/real_contacts.xlsx") + # print(contacts) + # write_new_contacts_to_excel(valid_contacts=contacts) + for mail in excel_reader.read_mails_and_pwd(): + MONGO_STORE_MANAGER.insert_email(mail) + diff --git a/src/utils/get_mail_list_and_pwd.py b/src/utils/get_mail_list_and_pwd.py new file mode 100644 index 0000000..5739a6b --- /dev/null +++ b/src/utils/get_mail_list_and_pwd.py @@ -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)