check black list before send request
This commit is contained in:
+23
-3
@@ -52,6 +52,17 @@ class MongoDbManager:
|
||||
except Exception as error:
|
||||
self.logger.info(error)
|
||||
|
||||
def get_blacklist_contacts(self) -> list:
|
||||
collection_name = BLACK_LIST
|
||||
black_list_contacts = []
|
||||
try:
|
||||
collection_to_use = self.db[collection_name]
|
||||
for document in collection_to_use.find():
|
||||
black_list_contacts.append(BlackContactPojo.from_firestore_dict(document))
|
||||
except Exception as error:
|
||||
self.logger.info(error)
|
||||
return black_list_contacts
|
||||
|
||||
def get_captcha_error_contacts_for_current_day(self) -> list:
|
||||
day = str(datetime.date.today())
|
||||
collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day
|
||||
@@ -71,9 +82,18 @@ class MongoDbManager:
|
||||
except Exception as error:
|
||||
self.logger.info(error)
|
||||
|
||||
def remove_contact_from_black_list(self, contact: ContactPojo):
|
||||
collection_name = BLACK_LIST
|
||||
collection = self.db[collection_name]
|
||||
to_delete = {'_id': contact.mail}
|
||||
try:
|
||||
collection.delete_one(to_delete)
|
||||
except Exception as error:
|
||||
self.logger.info(error)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
db_manager = MongoDbManager()
|
||||
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))
|
||||
black_list = db_manager.get_blacklist_contacts()
|
||||
for contact in black_list:
|
||||
print(contact)
|
||||
Reference in New Issue
Block a user