Merge branch 'feature/handle_black_list' into feature/check_results
# Conflicts: # src/db/mongo_manager.py
This commit is contained in:
@@ -7,6 +7,7 @@ from src.logs.AppLogging import init_logger
|
|||||||
from src.pojo.ModeEnum import ModeEnum
|
from src.pojo.ModeEnum import ModeEnum
|
||||||
from src.pojo.contact_pojo import ContactPojo
|
from src.pojo.contact_pojo import ContactPojo
|
||||||
from src.proxy.proxy_type import ProxyType
|
from src.proxy.proxy_type import ProxyType
|
||||||
|
from src.utils.black_list_checker import can_send_request
|
||||||
from src.utils.excel_reader import ExcelHelper
|
from src.utils.excel_reader import ExcelHelper
|
||||||
from src.workers.commandor_page import CommandorPage
|
from src.workers.commandor_page import CommandorPage
|
||||||
|
|
||||||
@@ -24,14 +25,16 @@ def start_book(start_number, end_number, store_choose_state=0, max_workers=10, p
|
|||||||
if len(all_contacts) <= end_number:
|
if len(all_contacts) <= end_number:
|
||||||
end_number = len(all_contacts)
|
end_number = len(all_contacts)
|
||||||
contacts = all_contacts[start_number - 1: end_number]
|
contacts = all_contacts[start_number - 1: end_number]
|
||||||
logger.info(contacts)
|
|
||||||
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
proxy = get_proxy(proxy_type)
|
proxy = get_proxy(proxy_type)
|
||||||
# start the task in thread
|
# start the task in thread
|
||||||
executor.submit(
|
if can_send_request(contact):
|
||||||
CommandorPage(contact, store_type=store_choose_state, proxy_type=proxy_type, mode=mode).start_page,
|
executor.submit(
|
||||||
proxy)
|
CommandorPage(contact, store_type=store_choose_state, proxy_type=proxy_type, mode=mode).start_page,
|
||||||
|
proxy)
|
||||||
|
else:
|
||||||
|
logger.info("do not send request --> skip")
|
||||||
|
|
||||||
|
|
||||||
def recheck_the_captcha_error_contacts(on_no_contact_found, store_type=0, mode: ModeEnum = ModeEnum.MANUAL,
|
def recheck_the_captcha_error_contacts(on_no_contact_found, store_type=0, mode: ModeEnum = ModeEnum.MANUAL,
|
||||||
|
|||||||
+23
-3
@@ -54,6 +54,17 @@ class MongoDbManager:
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
self.logger.info(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:
|
def get_all_successful_items_for_day(self) -> list:
|
||||||
params.oracle_log_sender.send_read_db_event("get_all_successful_items_for_day")
|
params.oracle_log_sender.send_read_db_event("get_all_successful_items_for_day")
|
||||||
collection_name = str(datetime.date.today())
|
collection_name = str(datetime.date.today())
|
||||||
@@ -96,9 +107,18 @@ class MongoDbManager:
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
self.logger.info(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__':
|
if __name__ == '__main__':
|
||||||
db_manager = MongoDbManager()
|
db_manager = MongoDbManager()
|
||||||
contact = ContactPojo(phone_number='0755667750', passport_number='123456789', last_name='PAN', first_name='Lei',
|
black_list = db_manager.get_blacklist_contacts()
|
||||||
mail='panleicim@gmail.com')
|
for contact in black_list:
|
||||||
print(db_manager.insert_blacklist_contact(contact))
|
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:
|
if len(data_sitekey) == 1:
|
||||||
key_with_comma = data_sitekey[0].split("=")[-1]
|
key_with_comma = data_sitekey[0].split("=")[-1]
|
||||||
key = key_with_comma.replace("\"", '')
|
key = key_with_comma.replace("\"", '')
|
||||||
self.logger.info("key is : " + key)
|
# self.logger.info("key is : " + key)
|
||||||
self.solve_captcha(key, handle_solution_received)
|
self.solve_captcha(key, handle_solution_received)
|
||||||
|
|
||||||
def solve_captcha(self, google_key: str, 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)
|
solution_res = requests.get(url_response)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
solution = solution_res.text
|
solution = solution_res.text
|
||||||
print(solution)
|
self.logger.info(solution)
|
||||||
handle_solution_received(solution.split("|")[-1])
|
handle_solution_received(solution.split("|")[-1])
|
||||||
|
|||||||
@@ -332,6 +332,7 @@ class CommandorPage:
|
|||||||
params.firebase_store_manager.save(result)
|
params.firebase_store_manager.save(result)
|
||||||
params.local_db_manager.handle_success(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.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:
|
if status is PublishType.SUCCESS:
|
||||||
self.on_success(result)
|
self.on_success(result)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|||||||
Reference in New Issue
Block a user