Merge branch 'feature/handle_black_list' into feature/check_results
# Conflicts: # src/db/mongo_manager.py
This commit is contained in:
+23
-3
@@ -54,6 +54,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_all_successful_items_for_day(self) -> list:
|
||||
params.oracle_log_sender.send_read_db_event("get_all_successful_items_for_day")
|
||||
collection_name = str(datetime.date.today())
|
||||
@@ -96,9 +107,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
|
||||
@@ -28,7 +28,7 @@ class SolveCaptcha:
|
||||
if len(data_sitekey) == 1:
|
||||
key_with_comma = data_sitekey[0].split("=")[-1]
|
||||
key = key_with_comma.replace("\"", '')
|
||||
self.logger.info("key is : " + key)
|
||||
# self.logger.info("key is : " + key)
|
||||
self.solve_captcha(key, handle_solution_received)
|
||||
|
||||
def solve_captcha(self, google_key: str, handle_solution_received):
|
||||
@@ -50,5 +50,5 @@ class SolveCaptcha:
|
||||
solution_res = requests.get(url_response)
|
||||
time.sleep(5)
|
||||
solution = solution_res.text
|
||||
print(solution)
|
||||
self.logger.info(solution)
|
||||
handle_solution_received(solution.split("|")[-1])
|
||||
|
||||
@@ -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