add model and serial to LinkToValid table
This commit is contained in:
+13
-1
@@ -1,6 +1,7 @@
|
||||
import datetime
|
||||
import logging
|
||||
import time
|
||||
from typing import Union
|
||||
|
||||
from pymongo import MongoClient
|
||||
|
||||
@@ -306,10 +307,17 @@ class MongoDbManager:
|
||||
_all_contact_list.append(ContactPojo.from_firestore_dict(document))
|
||||
return _all_contact_list
|
||||
|
||||
def save_links_to_validate(self, link: str, mail_address: str, _all_contact_list: list):
|
||||
def save_links_to_validate(self, link: str, mail_address: str, _all_contact_list: list,
|
||||
_item: Union[ReserveResultPojo, None]):
|
||||
collection_to_use = self.db[LINKS_TO_VALIDATE]
|
||||
updated_at = time.strftime("%H:%M:%S", time.localtime())
|
||||
_ip_country = "FR"
|
||||
_model = ""
|
||||
serial = ""
|
||||
if _item:
|
||||
_model = _item.source_from
|
||||
serial = _item.serial
|
||||
|
||||
# find ip_country info
|
||||
for _contact in _all_contact_list:
|
||||
if _contact.mail == mail_address:
|
||||
@@ -319,6 +327,8 @@ class MongoDbManager:
|
||||
collection_to_use.replace_one(filter={'_id': mail_address, }, replacement={
|
||||
u'url': link,
|
||||
u'email': mail_address,
|
||||
u'model': _model,
|
||||
u'serial': serial,
|
||||
u'ip_country': _ip_country,
|
||||
"updated_at": updated_at
|
||||
},
|
||||
@@ -326,6 +336,8 @@ class MongoDbManager:
|
||||
else:
|
||||
collection_to_use.replace_one(filter={'_id': link, }, replacement={
|
||||
u'url': link,
|
||||
u'model': _model,
|
||||
u'serial': serial,
|
||||
u'ip_country': _ip_country,
|
||||
"updated_at": updated_at
|
||||
},
|
||||
|
||||
+11
-18
@@ -11,9 +11,8 @@ from imapclient import IMAPClient
|
||||
|
||||
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from src.logs.AppLogging import init_logger
|
||||
from src.mail.mail_constants import DOMAIN_HOTMAIL, create_imap, show_folders
|
||||
from src.pojo.mail.mail_pojo import MailPojo, MailAddress
|
||||
from src.utils.excel_reader import ExcelHelper
|
||||
from src.mail.mail_constants import create_imap, show_folders
|
||||
from src.pojo.mail.mail_pojo import MailPojo
|
||||
from src.utils.timeutiles import is_time_between
|
||||
|
||||
VALIDATION_URL_SUBJECT_fr = 'Votre demande de rendez-vous'
|
||||
@@ -182,7 +181,7 @@ class MailReader():
|
||||
return mail_messages
|
||||
|
||||
|
||||
def need_to_valid_url(url: str, successful_items) -> bool:
|
||||
def need_to_valid_url(url: str, successful_items):
|
||||
# return True
|
||||
# if len(successful_items) == 0:
|
||||
# return False
|
||||
@@ -193,16 +192,16 @@ def need_to_valid_url(url: str, successful_items) -> bool:
|
||||
for item in successful_items:
|
||||
if item.id == id:
|
||||
if item.url_validated is not None:
|
||||
return not item.url_validated
|
||||
return item, not item.url_validated
|
||||
else:
|
||||
# if url_validated is None
|
||||
if item.url_validated is not None:
|
||||
return not item.url_validated
|
||||
return True
|
||||
return True
|
||||
return item, not item.url_validated
|
||||
return item, True
|
||||
return None, True
|
||||
else:
|
||||
print("id not valid:{}".format(id))
|
||||
return False
|
||||
return None, False
|
||||
|
||||
|
||||
def need_to_check_email(mail: str, successful_items) -> bool:
|
||||
@@ -259,18 +258,12 @@ def read_mails():
|
||||
_all_contact_list = MONGO_STORE_MANAGER.get_all_contacts_to_book()
|
||||
with ThreadPoolExecutor(max_workers=10) as executor:
|
||||
for mail in mails_messages:
|
||||
# if mail.isImapClient:
|
||||
# match = re.search(PART_VALIDATION_URL_REGEX, mail.body.replace("\n", ""))
|
||||
# else:
|
||||
match = re.search(VALIDATION_URL_REGEX, mail.body)
|
||||
if match:
|
||||
# url_to_validate = match.group(0)
|
||||
# if mail.isImapClient:
|
||||
# url = "https://rendezvousparis.hermes.com/" + url_to_validate.replace("3D", "")
|
||||
# else:
|
||||
url = match.group(0)
|
||||
if need_to_valid_url(url, _refreshed_successful_items):
|
||||
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.to_address, _all_contact_list)
|
||||
_item, is_need_to = need_to_valid_url(url, _refreshed_successful_items)
|
||||
if is_need_to:
|
||||
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.to_address, _all_contact_list, _item)
|
||||
# url_validator = LinkValidator(url)
|
||||
print("need to validate url: " + url)
|
||||
# executor.submit(url_validator.start_page, params.get_proxy(ProxyType.OXYLABS), False)
|
||||
|
||||
@@ -39,6 +39,7 @@ class ReserveResultPojo:
|
||||
validated_at = None
|
||||
ip_address = None
|
||||
ua = ""
|
||||
model = ""
|
||||
serial = ""
|
||||
|
||||
def __hash__(self):
|
||||
@@ -109,8 +110,8 @@ class ReserveResultPojo:
|
||||
if 'message' in source:
|
||||
message = source['message']
|
||||
result.message = message
|
||||
if 'source' in source:
|
||||
source_from = source['source']
|
||||
if 'source_from' in source:
|
||||
source_from = source['source_from']
|
||||
result.source_from = source_from
|
||||
if 'sim_position' in source:
|
||||
sim_position = source['sim_position']
|
||||
|
||||
Reference in New Issue
Block a user