check black list before send request

This commit is contained in:
Lei PAN
2022-07-06 18:08:00 +02:00
parent d495308a1f
commit 2a339be86e
4 changed files with 47 additions and 7 deletions
+23 -3
View File
@@ -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)