Files
appointment_request/workers/find_infos_from_results.py
T
2024-06-02 11:36:48 +02:00

73 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import glob
import re
from db.mongo_manager import MONGO_STORE_MANAGER
from models import AcceptedResultPojo
CONFIRMATION_SENTENCE = "Nous avons le plaisir de vous confirmer votre rendez-vous"
TIME_REGEX = "([0-1]?[0-9]|2[0-3]):[0-5][0-9]"
def get_store_info_from_html_content(_content):
store = ""
if "Faubourg" in _content:
print("found")
store = "Faubourg"
elif "George V" in _content:
store = "George V"
elif "Sèvres" in _content:
store = "BM"
time_results = re.search(TIME_REGEX, _content)
time = time_results[0]
return store, time
def find_ids_from_results():
_html_files = glob.glob("results/*.html")
info_list = []
for _file in _html_files:
f = open(_file, "r")
_content = f.read()
if CONFIRMATION_SENTENCE in _content:
appointment_info = get_store_info_from_html_content(_content)
_id = _file.split("_")[-1].split(".")[0]
info_list.append((_id, appointment_info))
return info_list
# info_list (id, (store, time))
def get_appointment_info_from_id(info_list: list):
_all_items = MONGO_STORE_MANAGER.get_all_successful_items_for_yesterday()
_all_contact_list = MONGO_STORE_MANAGER.get_all_contact_to_book_list()
_all_register_account = MONGO_STORE_MANAGER.get_all_registered_users()
accepted_appointments = []
for _item in _all_items:
for _info in info_list:
if _item.id == _info[0]:
_accepted = AcceptedResultPojo.get_accepted_result_from(_item, MONGO_STORE_MANAGER, _all_contact_list)
_accepted.store = _info[1][0]
_accepted.time = _info[1][1]
accepted_appointments.append(_accepted)
for _accepted in accepted_appointments:
for user in _all_register_account:
if user.mail == _accepted.email:
_accepted.account_password = user.password
return accepted_appointments
if __name__ == '__main__':
accepted_appointments = get_appointment_info_from_id(find_ids_from_results())
for _accepted in accepted_appointments:
print("""
姓名:{} ({} {})
电话:{} ,邮箱:{}
邮箱密码:{}
护照: {},
约会url:{},
账户密码:{}""".format(_accepted.name, _accepted.store,
_accepted.time,
_accepted.phone, _accepted.email,
_accepted.mail_password,
_accepted.passport, _accepted.url
, _accepted.account_password))