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