add black list contact to db
This commit is contained in:
+17
-1
@@ -3,10 +3,12 @@ import logging
|
|||||||
|
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||||
|
from pojo.black_contact import BlackContactPojo
|
||||||
from pojo.contact_pojo import ContactPojo
|
from pojo.contact_pojo import ContactPojo
|
||||||
|
|
||||||
MONGO_DB_URL = "mongo.lpaconsulting.fr"
|
MONGO_DB_URL = "mongo.lpaconsulting.fr"
|
||||||
CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_"
|
CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_"
|
||||||
|
BLACK_LIST = "BLACK_LIST"
|
||||||
|
|
||||||
|
|
||||||
class MongoDbManager:
|
class MongoDbManager:
|
||||||
@@ -37,6 +39,18 @@ class MongoDbManager:
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
self.logger.info(error)
|
self.logger.info(error)
|
||||||
|
|
||||||
|
def insert_blacklist_contact(self, contact: ContactPojo):
|
||||||
|
collection_name = BLACK_LIST
|
||||||
|
black_contact = BlackContactPojo(contact.phone, contact.passport, contact.last_name, contact.first_name,
|
||||||
|
contact.mail)
|
||||||
|
try:
|
||||||
|
collection_to_use = self.db[collection_name]
|
||||||
|
collection_to_use.replace_one(filter={'_id': black_contact.mail, },
|
||||||
|
replacement=black_contact.to_firestore_dict(),
|
||||||
|
upsert=True)
|
||||||
|
except Exception as error:
|
||||||
|
self.logger.info(error)
|
||||||
|
|
||||||
def get_captcha_error_contacts_for_current_day(self) -> list:
|
def get_captcha_error_contacts_for_current_day(self) -> list:
|
||||||
day = str(datetime.date.today())
|
day = str(datetime.date.today())
|
||||||
collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day
|
collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day
|
||||||
@@ -59,4 +73,6 @@ class MongoDbManager:
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
db_manager = MongoDbManager()
|
db_manager = MongoDbManager()
|
||||||
print(db_manager.get_captcha_error_contacts_for_current_day())
|
contact = ContactPojo(phone_number='0755667750', passport_number='123456789', last_name='PAN', first_name='Lei',
|
||||||
|
mail='panleicim@gmail.com')
|
||||||
|
print(db_manager.insert_blacklist_contact(contact))
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import time
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from pojo.contact_pojo import ContactPojo
|
||||||
|
|
||||||
|
|
||||||
|
class BlackContactPojo(ContactPojo):
|
||||||
|
update_at_in_s: float
|
||||||
|
|
||||||
|
def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, mail: str,
|
||||||
|
update_at_in_s: Union[float, None] = None,
|
||||||
|
ccid: str = "",
|
||||||
|
position: int = 0, ):
|
||||||
|
super().__init__(phone_number, passport_number, last_name, first_name, mail, ccid, position)
|
||||||
|
if update_at_in_s:
|
||||||
|
self.update_at_in_s = update_at_in_s
|
||||||
|
else:
|
||||||
|
self.update_at_in_s = time.time()
|
||||||
|
|
||||||
|
def to_firestore_dict(self):
|
||||||
|
dest = super().to_firestore_dict()
|
||||||
|
dest.setdefault(u'update_at_in_s', self.update_at_in_s)
|
||||||
|
return dest
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_firestore_dict(source):
|
||||||
|
ccid = source['ccid']
|
||||||
|
phone = source['phone']
|
||||||
|
position = source['position']
|
||||||
|
passport = source['passport']
|
||||||
|
email = source['mail']
|
||||||
|
last_name = source['last_name']
|
||||||
|
first_name = source['first_name']
|
||||||
|
update_at_in_s = source['update_at_in_s']
|
||||||
|
result = BlackContactPojo(ccid=ccid, phone_number=phone, passport_number=passport, position=position,
|
||||||
|
mail=email, update_at_in_s=update_at_in_s,
|
||||||
|
last_name=last_name, first_name=first_name)
|
||||||
|
return result
|
||||||
@@ -50,8 +50,8 @@ class ContactPojo:
|
|||||||
position = source['position']
|
position = source['position']
|
||||||
passport = source['passport']
|
passport = source['passport']
|
||||||
email = source['mail']
|
email = source['mail']
|
||||||
lastName = source['last_name']
|
last_name = source['last_name']
|
||||||
firstName = source['last_name']
|
first_name = source['first_name']
|
||||||
result = ContactPojo(ccid=ccid, phone_number=phone, passport_number=passport, position=position, mail=email,
|
result = ContactPojo(ccid=ccid, phone_number=phone, passport_number=passport, position=position, mail=email,
|
||||||
last_name=lastName, first_name=firstName)
|
last_name=last_name, first_name=first_name)
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ TOO_MANY_REQUEST_ERROR_MESSAGE = "Due to a large number of requests"
|
|||||||
TOO_MANY_REQUEST_ERROR_MESSAGE_FR = "Suite à un trop grand nombre de demandes"
|
TOO_MANY_REQUEST_ERROR_MESSAGE_FR = "Suite à un trop grand nombre de demandes"
|
||||||
CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
|
CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
|
||||||
CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué"
|
CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué"
|
||||||
TIME_OUT = 10*60*1000 #10 mins
|
TIME_OUT = 10 * 60 * 1000 # 10 mins
|
||||||
OTP_TIMEOUT = 240
|
OTP_TIMEOUT = 240
|
||||||
PAGE_TIMEOUT = 40000
|
PAGE_TIMEOUT = 40000
|
||||||
|
|
||||||
@@ -252,11 +252,12 @@ class CommandorPage:
|
|||||||
self.is_finished = True
|
self.is_finished = True
|
||||||
self.termine()
|
self.termine()
|
||||||
elif TOO_MANY_REQUEST_ERROR_MESSAGE in erro_content or TOO_MANY_REQUEST_ERROR_MESSAGE_FR in erro_content:
|
elif TOO_MANY_REQUEST_ERROR_MESSAGE in erro_content or TOO_MANY_REQUEST_ERROR_MESSAGE_FR in erro_content:
|
||||||
# this email has been already used
|
# this email is in black list
|
||||||
if not self.is_finished:
|
if not self.is_finished:
|
||||||
params.local_db_manager.insert_or_update(
|
params.local_db_manager.insert_or_update(
|
||||||
get_captcha_error_contact_from_contact(self.contact, TOO_MANY_REQUEST_ERROR))
|
get_captcha_error_contact_from_contact(self.contact, TOO_MANY_REQUEST_ERROR))
|
||||||
params.oracle_log_sender.send_too_many_error(self.contact)
|
params.oracle_log_sender.send_too_many_error(self.contact)
|
||||||
|
params.mongo_store_manager.insert_blacklist_contact(self.contact)
|
||||||
self.is_finished = True
|
self.is_finished = True
|
||||||
self.termine()
|
self.termine()
|
||||||
elif CAPTCHA_ERROR_MESSAGE in erro_content or CAPTCHA_ERROR_MESSAGE_FR in erro_content:
|
elif CAPTCHA_ERROR_MESSAGE in erro_content or CAPTCHA_ERROR_MESSAGE_FR in erro_content:
|
||||||
|
|||||||
Reference in New Issue
Block a user