remove unused codes

This commit is contained in:
2022-05-10 19:23:30 +02:00
parent de5bcb2698
commit a9a569a314
8 changed files with 41 additions and 390 deletions
+38 -63
View File
@@ -10,18 +10,13 @@ from gsmmodem import GsmModem
import params
from workers.commandor_page import CommandorPage
from logs.AppLogging import init_logger
from modems.ModemPool import ModemPool
from modems.card_pool import CardPool
from params import MODEM_POOL_PORTS, CARD_POOL_PORT, oracle_log_sender
from params import oracle_log_sender
from pojo.serial_modem import SerialModem
from utils.excel_reader import ExcelHelper
OTP_TIMEOUT = 240
current_gsm_modem = None
card_pool = CardPool(CARD_POOL_PORT)
# used to save the current slot position
current_card_pool_slot = 1
current_sim_position = 1
init_logger()
logger = logging.getLogger()
@@ -51,62 +46,42 @@ def create_modem_for_port(port: str) -> Union[SerialModem, None]:
return serial_modem
def init_modems() -> list:
modems = []
for port in params.MODEM_POOL_PORTS:
serial_modem = create_modem_for_port(port)
if serial_modem:
modems.append(serial_modem)
return modems
def start_book(start_slot_number, end_slot_number, store=0):
slot_list = list(range(start_slot_number, end_slot_number + 1))
random.shuffle(slot_list)
for i in slot_list:
random.shuffle(params.MODEM_POOL_PORTS)
card_pool.reset()
logger.info("will switch to " + str(i))
global current_card_pool_slot
current_card_pool_slot = i
card_pool.switch_to_slot(i)
modem_pool = ModemPool(MODEM_POOL_PORTS)
modem_pool.reset_all_modems()
modem_list = init_modems()
# read the contact, and contact the 2 objects together
excel_reader = ExcelHelper()
contacts = excel_reader.read_contacts()
global current_sim_position
current_sim_position = 0
with ThreadPoolExecutor(max_workers=10) as executor:
for modem in modem_list:
current_sim_position = current_sim_position + 1
try:
modem.get_ccid()
# find the contact with ccid
contact = [contact for contact in contacts if
contact.ccid.replace("F", "") == modem.ccid.replace("F", "")]
if len(contact) > 0:
modem.phone_number = contact[0].phone
modem.contact = contact[0]
else:
logger.info("contact not found for this ccid:{}".format(modem.ccid))
error_msg = "slot({}):sim({}):ccid({})".format(i, current_sim_position, modem.ccid)
oracle_log_sender.send_contact_not_found(error_msg)
modem.modem.close()
continue
if modem.contact:
logger.info("contact found for this ccid")
signal = modem.modem.signalStrength
logger.info("信号强度: " + str(signal))
proxy = get_proxy(modem.phone_number)
commandor = CommandorPage(modem, sim_position=current_sim_position,
slot_position=current_card_pool_slot, store_type=store)
# start the task in thread
executor.submit(commandor.start_page, proxy)
except Exception as error:
print(error)
continue
def start_book(start_number, end_number, store=0):
# read the contact, and contact the 2 objects together
excel_reader = ExcelHelper()
contacts = excel_reader.read_contacts()[start_number - 1: end_number - 1]
print(contacts)
# for i in contacts_range:
# logger.info("will switch to contact {}".format(i))
# with ThreadPoolExecutor(max_workers=10) as executor:
# for modem in modem_list:
# current_sim_position = current_sim_position + 1
# try:
# modem.get_ccid()
# # find the contact with ccid
# contact = [contact for contact in contacts if
# contact.ccid.replace("F", "") == modem.ccid.replace("F", "")]
# if len(contact) > 0:
# modem.phone_number = contact[0].phone
# modem.contact = contact[0]
# else:
# logger.info("contact not found for this ccid:{}".format(modem.ccid))
# error_msg = "slot({}):sim({}):ccid({})".format(i, current_sim_position, modem.ccid)
# oracle_log_sender.send_contact_not_found(error_msg)
# modem.modem.close()
# continue
# if modem.contact:
# logger.info("contact found for this ccid")
# signal = modem.modem.signalStrength
# logger.info("信号强度: " + str(signal))
# proxy = get_proxy(modem.phone_number)
# commandor = CommandorPage(modem, sim_position=current_sim_position,
# slot_position=current_card_pool_slot, store_type=store)
# # start the task in thread
# executor.submit(commandor.start_page, proxy)
# except Exception as error:
# print(error)
# continue
def get_proxy(phone_number):
@@ -123,4 +98,4 @@ def get_proxy(phone_number):
if __name__ == '__main__':
# 修改起始行,结束行, 第三个参数store等于0的时候是随机,传入1的时候是总店
start_book(17, 17, store=0)
start_book(2, 18, store=0)