def run(self, command):
     logger.attr('Command', command)
     self.config.start_time = datetime.now()
     self.device = Device(config=self.config)
     while 1:
         try:
             self.__getattribute__(command.lower())()
             break
         except GameNotRunningError as e:
             logger.warning(e)
             az = LoginHandler(self.config, device=self.device)
             az.app_restart()
             az.ensure_no_unfinished_campaign()
             continue
         except GameTooManyClickError as e:
             logger.warning(e)
             az = LoginHandler(self.config, device=self.device)
             az.app_restart()
             az.ensure_no_unfinished_campaign()
             continue
         except GameStuckError as e:
             logger.warning(e)
             self.save_error_log()
             az = LoginHandler(self.config, device=self.device)
             az.handle_game_stuck()
             continue
         except Exception as e:
             logger.exception(e)
             self.save_error_log()
             break
    def run(self, command):
        self.config.start_time = datetime.now()
        try:
            self.device = Device(config=self.config)
            self.__getattribute__(command.lower())()
        except Exception as e:
            logger.exception(e)

            if self.config.ENABLE_ERROR_LOG_AND_SCREENSHOT_SAVE:
                folder = f'./log/error/{int(time.time() * 1000)}'
                logger.info(f'Saving error: {folder}')
                os.mkdir(folder)
                for data in logger.screenshot_deque:
                    image_time = datetime.strftime(data['time'],
                                                   '%Y-%m-%d_%H-%M-%S-%f')
                    image = handle_sensitive_image(data['image'])
                    image.save(f'{folder}/{image_time}.png')
                with open(log_file, 'r') as f:
                    start = 0
                    for index, line in enumerate(f.readlines()):
                        if re.search('\+-{15,}\+', line):
                            start = index
                with open(log_file, 'r') as f:
                    text = f.readlines()[start - 2:]
                    text = handle_sensitive_logs(text)
                with open(f'{folder}/log.txt', 'w') as f:
                    f.writelines(text)
 def device(self):
     try:
         from module.device.device import Device
         device = Device(config=self.config)
         return device
     except Exception as e:
         logger.exception(e)
         exit(1)
Exemple #4
0
 def device(self):
     try:
         from module.device.device import Device
         device = Device(config=self.config)
         return device
     except RequestHumanTakeover:
         logger.critical('Request human takeover')
         exit(1)
     except Exception as e:
         logger.exception(e)
         exit(1)
Exemple #5
0
 def __init__(self, config, device=None):
     """
     Args:
         config (AzurLaneConfig):
         device (Device):
     """
     self.config = config
     self.interval_timer = {}
     if device is not None:
         self.device = device
     else:
         self.device = Device(config=config)
    def __init__(self, config, device=None):
        """
        Args:
            config (AzurLaneConfig, str):
            device (Device):
        """
        if isinstance(config, str):
            self.config = AzurLaneConfig(config)
        else:
            self.config = config
        if device is not None:
            self.device = device
        else:
            self.device = Device(config=self.config)

        self.interval_timer = {}
Exemple #7
0
 def __init__(self, config, device=None, task=None):
     """
     Args:
         config (AzurLaneConfig, str): Name of the user config under ./config
         device (Device): To reuse a device. If None, create a new Device object.
         task (str): Bind a task only for dev purpose. Usually to be None for auto task scheduling.
     """
     if isinstance(config, str):
         self.config = AzurLaneConfig(config, task=task)
     else:
         self.config = config
     if device is not None:
         self.device = device
     else:
         self.device = Device(config=self.config)
     self.interval_timer = {}