check if contact already requested or not
This commit is contained in:
@@ -18,7 +18,7 @@ logger = logging.getLogger()
|
||||
logger.addHandler(logging.StreamHandler(stream=sys.stdout))
|
||||
|
||||
|
||||
def start_book(start_number, end_number, store_choose_state=0, max_workers=10, proxy_type=ProxyType.BRIGHT_DATA,
|
||||
def start_book(start_number, end_number, store_choose_state=0, max_workers=1, proxy_type=ProxyType.BRIGHT_DATA,
|
||||
mode: ModeEnum = ModeEnum.MANUAL, headless=False):
|
||||
# read the contact, and contact the 2 objects together
|
||||
excel_reader = ExcelHelper()
|
||||
@@ -40,7 +40,7 @@ def start_book(start_number, end_number, store_choose_state=0, max_workers=10, p
|
||||
|
||||
|
||||
def recheck_the_captcha_error_contacts(on_no_contact_found, store_type=0, mode: ModeEnum = ModeEnum.MANUAL,
|
||||
max_workers=10):
|
||||
max_workers=20):
|
||||
# get all the contacts in captcha error
|
||||
contact_list = MONGO_STORE_MANAGER.get_captcha_error_contacts_for_current_day()
|
||||
if len(contact_list) == 0:
|
||||
@@ -61,5 +61,5 @@ def get_proxy(proxy_type=ProxyType.BRIGHT_DATA):
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 修改联系人行,结束联系人行 第三个参数store等于0的时候是随机,传入1的时候是总店
|
||||
start_book(101, 200, store_choose_state=1, mode=ModeEnum.AUTOMATIC, headless=True)
|
||||
# recheck_the_captcha_error_contacts(store_type=0, mode=ModeEnum.AUTOMATIC, on_no_contact_found=lambda: None)
|
||||
start_book(1000, 1171, store_choose_state=1, mode=ModeEnum.AUTOMATIC, headless=False)
|
||||
# recheck_the_captcha_error_contacts(store_type=1, mode=ModeEnum.AUTOMATIC, on_no_contact_found=lambda: None)
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
import time
|
||||
|
||||
from src import params, definitions
|
||||
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from src.pojo.contact_pojo import ContactPojo
|
||||
|
||||
SEVEN_DAYS_IN_S = 7 * 24 * 3600
|
||||
|
||||
|
||||
def can_send_request(contact: ContactPojo) -> bool:
|
||||
def is_already_sent(contact: ContactPojo) -> bool:
|
||||
already_sent_contacts = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
for required_contact in already_sent_contacts:
|
||||
if contact.mail == required_contact.email:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def is_in_white_list(contact: ContactPojo) -> bool:
|
||||
black_list = MONGO_STORE_MANAGER.get_blacklist_contacts()
|
||||
for black_contact in black_list:
|
||||
if contact.mail == black_contact.mail:
|
||||
@@ -15,3 +22,7 @@ def can_send_request(contact: ContactPojo) -> bool:
|
||||
return black_contact.update_at_in_s + SEVEN_DAYS_IN_S < time.time()
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def can_send_request(contact: ContactPojo) -> bool:
|
||||
return is_in_white_list(contact) and (not is_already_sent(contact=contact))
|
||||
|
||||
@@ -46,10 +46,12 @@ class SolveCaptcha:
|
||||
url_response = "http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY,
|
||||
self.captcha_id)
|
||||
solution = CAPCHA_NOT_READY
|
||||
while solution == CAPCHA_NOT_READY:
|
||||
status_code = 1
|
||||
while solution == CAPCHA_NOT_READY or status_code != 200:
|
||||
solution_res = requests.get(url_response)
|
||||
time.sleep(5)
|
||||
solution = solution_res.text
|
||||
self.logger.info("response code: " + str(res.status_code))
|
||||
status_code = res.status_code
|
||||
# self.logger.info(solution)
|
||||
handle_solution_received(solution.split("|")[-1])
|
||||
|
||||
@@ -328,7 +328,7 @@ class CommandorPage:
|
||||
self.captcha_solver.start(self.fill_captcha_solution)
|
||||
|
||||
def fill_captcha_solution(self, solution):
|
||||
self.logger.info("will input solution: " + solution)
|
||||
self.logger.info("will input solution")
|
||||
try:
|
||||
self.page.evaluate("""(solution)=>{
|
||||
document.getElementById("g-recaptcha-response").innerHTML=solution;}""", solution)
|
||||
|
||||
Reference in New Issue
Block a user