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)
|
||||
@@ -0,0 +1,16 @@
|
||||
import time
|
||||
|
||||
from src import params
|
||||
from src.pojo.contact_pojo import ContactPojo
|
||||
|
||||
SEVEN_DAYS_IN_S = 7 * 24 * 3600
|
||||
|
||||
|
||||
def can_send_request(contact: ContactPojo) -> bool:
|
||||
black_list = params.mongo_store_manager.get_blacklist_contacts()
|
||||
for black_contact in black_list:
|
||||
if contact.mail == black_contact.mail:
|
||||
# check date
|
||||
return black_contact.update_at_in_s + SEVEN_DAYS_IN_S < time.time()
|
||||
|
||||
return True
|
||||
@@ -332,6 +332,7 @@ class CommandorPage:
|
||||
params.firebase_store_manager.save(result)
|
||||
params.local_db_manager.handle_success(result)
|
||||
params.mongo_store_manager.delete_captcha_error_contact_for_current_day(self.contact)
|
||||
params.mongo_store_manager.remove_contact_from_black_list(self.contact)
|
||||
if status is PublishType.SUCCESS:
|
||||
self.on_success(result)
|
||||
time.sleep(2)
|
||||
|
||||
Reference in New Issue
Block a user