Merge branch 'feature/black_list' into feature/pyapp
# Conflicts: # src/db/mongo_manager.py # src/pojo/black_contact.py
This commit is contained in:
+19
-4
@@ -2,12 +2,13 @@ import datetime
|
||||
import logging
|
||||
|
||||
from pymongo import MongoClient
|
||||
|
||||
from src.pojo.ReserveResultPojo import ReserveResultPojo
|
||||
from src.pojo.contact_pojo import ContactPojo
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||
from pojo.black_contact import BlackContactPojo
|
||||
from pojo.contact_pojo import ContactPojo
|
||||
|
||||
MONGO_DB_URL = "mongo.lpaconsulting.fr"
|
||||
CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_"
|
||||
BLACK_LIST = "BLACK_LIST"
|
||||
|
||||
|
||||
class MongoDbManager:
|
||||
@@ -38,6 +39,18 @@ class MongoDbManager:
|
||||
except Exception as 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:
|
||||
day = str(datetime.date.today())
|
||||
collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day
|
||||
@@ -60,4 +73,6 @@ class MongoDbManager:
|
||||
|
||||
if __name__ == '__main__':
|
||||
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']
|
||||
passport = source['passport']
|
||||
email = source['mail']
|
||||
lastName = source['last_name']
|
||||
firstName = source['last_name']
|
||||
last_name = source['last_name']
|
||||
first_name = source['first_name']
|
||||
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
|
||||
|
||||
@@ -252,11 +252,12 @@ class CommandorPage:
|
||||
self.is_finished = True
|
||||
self.termine()
|
||||
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:
|
||||
params.local_db_manager.insert_or_update(
|
||||
get_captcha_error_contact_from_contact(self.contact, TOO_MANY_REQUEST_ERROR))
|
||||
params.oracle_log_sender.send_too_many_error(self.contact)
|
||||
params.mongo_store_manager.insert_blacklist_contact(self.contact)
|
||||
self.is_finished = True
|
||||
self.termine()
|
||||
elif CAPTCHA_ERROR_MESSAGE in erro_content or CAPTCHA_ERROR_MESSAGE_FR in erro_content:
|
||||
|
||||
Reference in New Issue
Block a user