From 46cad41d4cd88953ee1fd561cb88e252b23b149d Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 26 Jun 2025 17:43:13 +0200 Subject: [PATCH] add mail help for lan messagerie --- src/pojo/LinkPojo.py | 24 ++++++++++ src/utils/mail/lan_mail_helper.py | 73 +++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/pojo/LinkPojo.py create mode 100644 src/utils/mail/lan_mail_helper.py diff --git a/src/pojo/LinkPojo.py b/src/pojo/LinkPojo.py new file mode 100644 index 0000000..7f75958 --- /dev/null +++ b/src/pojo/LinkPojo.py @@ -0,0 +1,24 @@ +class LinkPojo(): + def __init__(self, url, email, model, serial, updated_at, ip_country): + self.url = url + self.email = email + self.model = model + self.serial = serial + self.updated_at = updated_at + self.ip_country = ip_country + + @staticmethod + def from_firestore_dict(source): + updated_at = source['updated_at'] + email = source['email'] + model = "" + if 'model' in source: + model = source['model'] + serial = source['serial'] + url = source['url'] + ip_country = "FR" + if source.get('ip_country'): + ip_country = source['ip_country'] + result = LinkPojo(email=email, url=url, model=model, serial=serial, updated_at=updated_at, + ip_country=ip_country) + return result diff --git a/src/utils/mail/lan_mail_helper.py b/src/utils/mail/lan_mail_helper.py new file mode 100644 index 0000000..1cd2b8e --- /dev/null +++ b/src/utils/mail/lan_mail_helper.py @@ -0,0 +1,73 @@ +import time + +import requests + +from src.db.mongo_manager import MONGO_STORE_MANAGER + +host = "https://authhk.bhdata.com:30015/bhmailer?uid=482391396&sign=32d7748da00047b9a1054c81a5750365" + +HERMES_EMAIL = "no-reply@hermes.com" + + +def get_api_info(): + _time = str(int(time.time() * 1000)) + _api_info = host + "&act=getApiInfo&t=" + _time + print(_api_info) + res = requests.get(_api_info, verify=False) + print(res.text) + + +def get_mail(mail: str): + _time = str(int(time.time() * 1000)) + _hermes_mail = "Votre demande de rendez-vous" + _api_info = host + "&act=getMail&email={}&title={}&t={}".format(mail, _hermes_mail, _time) + print(_api_info) + res = requests.get(_api_info, verify=False) + print(res.text) + + +def check_mail(mail: str): + _time = str(int(time.time() * 1000)) + _hermes_mail = HERMES_EMAIL + _api_info = host + "&act=checkMail&email={}&from={}&t={}".format(mail, _hermes_mail, _time) + print(_api_info) + res = requests.get(_api_info, verify=False) + print(res.text) + + +def get_account(mail: str): + _time = str(int(time.time() * 1000)) + _api_info = host + "&act=getAccount&email={}&t={}".format(mail, _time) + print(_api_info) + res = requests.get(_api_info, verify=False) + print(res.text) + + +def filter_mail_with_links(_mail_list_to_filter): + _new_mail_list = [] + _link_to_validate_list = MONGO_STORE_MANAGER.get_links_to_validate() + for _mail in _mail_list_to_filter: + _to_add = True + for _link in _link_to_validate_list: + if _link.email == _mail: + _to_add = False + if _to_add: + _new_mail_list.append(_mail) + return _new_mail_list + + +def get_mail_list_to_check(): + successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day() + _mail_list = [] + for _item in successful_items: + if _item.url_validated is None or _item.url_validated != True: + _mail_list.append(_item.mail) + return _mail_list + + +if __name__ == '__main__': + _mail_list_before_filter = get_mail_list_to_check() + _mails = filter_mail_with_links(_mail_list_before_filter) + for _mail in _mails: + if "outlook.com" in _mail or "hotmail.com" in _mail: + check_mail(_mail)