Files
appointment_request/workers/find_infos_from_results.py
T

115 lines
4.9 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 datetime
import glob
import re
from db.mongo_manager import MONGO_STORE_MANAGER, MongoDbManager
from models.AcceptedResultPojo import AcceptedResultPojo
from models.ReserveResultPojo import ReserveResultPojo
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 = 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
def get_accepted_result_from(reserve_pojo: ReserveResultPojo, mongo_db_manager: MongoDbManager,
all_contact_list) -> AcceptedResultPojo:
if reserve_pojo.lastName is None or len(reserve_pojo.lastName) == 0:
for _contact in all_contact_list:
if _contact.mail == reserve_pojo.email:
reserve_pojo.lastName = _contact.last_name
reserve_pojo.firstName = _contact.first_name
reserve_pojo.phone = _contact.phone
reserve_pojo.passport = _contact.passport
if reserve_pojo is None:
# send email even there are no reserve info
return AcceptedResultPojo(id="", msg="", slot_position=0, sim_position=0,
passport="", email="", phone="",
name="", ccid="",
url="", created_at="", validated_at="")
else:
toReturn = AcceptedResultPojo(id=reserve_pojo.id, msg=reserve_pojo.message,
slot_position=reserve_pojo.slot_position,
sim_position=reserve_pojo.sim_position,
passport=reserve_pojo.passport, email=reserve_pojo.email,
phone=reserve_pojo.phone,
name="{} {}".format(reserve_pojo.lastName, reserve_pojo.firstName),
firstName=reserve_pojo.firstName, lastName=reserve_pojo.lastName,
ccid=reserve_pojo.ccid,
url=reserve_pojo.url, created_at=reserve_pojo.created_at,
validated_at=reserve_pojo.validated_at)
toReturn.mail_password = mongo_db_manager.get_code_for_email(reserve_pojo.email)
return toReturn
def migre_accepted_appointment(day: str, accepted_appointments: list):
# get successful item from firestore
for accepted_pojo in accepted_appointments:
accepted_pojo.day = day
accepted_pojo.accepted_at = datetime.datetime.strptime(day, '%Y-%m-%d').timestamp()
MONGO_STORE_MANAGER.insert_accepted_reserve(accepted_pojo)
if __name__ == '__main__':
accepted_appointments = get_appointment_info_from_id(find_ids_from_results())
migre_accepted_appointment("2024-06-01", accepted_appointments)
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))