46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
import logging
|
|
import sys
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
import params
|
|
from logs.AppLogging import init_logger
|
|
from utils.excel_reader import ExcelHelper
|
|
from workers.commandor_page import CommandorPage
|
|
|
|
# used to save the current slot position
|
|
init_logger()
|
|
logger = logging.getLogger()
|
|
logger.addHandler(logging.StreamHandler(stream=sys.stdout))
|
|
|
|
|
|
def start_book(start_number, end_number, store_choose_state=0, max_workers=10):
|
|
# read the contact, and contact the 2 objects together
|
|
excel_reader = ExcelHelper()
|
|
all_contacts = excel_reader.read_contacts()
|
|
if len(all_contacts) <= end_number:
|
|
end_number = len(all_contacts)
|
|
contacts = all_contacts[start_number - 1: end_number]
|
|
logger.info(contacts)
|
|
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
|
for contact in contacts:
|
|
proxy = get_proxy(contact.phone)
|
|
# start the task in thread
|
|
executor.submit(CommandorPage(contact, store_type=store_choose_state).start_page, proxy)
|
|
|
|
|
|
def get_proxy(phone_number):
|
|
random_id_number = str(phone_number)[1:len(str(phone_number))]
|
|
proxy_username = "panleicim-res-fr-" + random_id_number
|
|
logger.info("proxy_username is " + proxy_username)
|
|
proxy = {
|
|
"server": params.PROXY_SERVER,
|
|
"username": proxy_username,
|
|
"password": params.PROXY_PASSWORD
|
|
}
|
|
return proxy
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# 修改联系人行,结束联系人行 第三个参数store等于0的时候是随机,传入1的时候是总店
|
|
start_book(1, 1, store_choose_state=0)
|