Esempio n. 1
0
def find_res(res, res_path=None):
    res_path = res_path or "C:/eBEST/xingAPI/Res/"

    res_file_name = os.path.join(res_path, res + ".res")
    if not os.path.isfile(res_file_name):
        logger.fatal(f"can't find {res_file_name}")
        raise FileNotFoundError
    return res_file_name
Esempio n. 2
0
def try_request(url):
    print(url)
    try:
        logger.debug(f'try_request: Trying HTTP get for url {url}')
        data = requests.get(url)
        return data
    except:
        logger.fatal(f'try_request: Exception occurred in requests.get()')
Esempio n. 3
0
 def __check_args_length(must: int,
                         argname: str,
                         soft: bool = False) -> bool:
     if len(passed_args) < must:
         if not soft:
             logger.fatal('MISSING ARGUMENT: [%s]' % argname)
             raise Exception('manual interruption')
         logger.error('MISSING ARGUMENT: [%s]' % argname)
Esempio n. 4
0
 def OnLogin(self, code, msg):
     if code == "0000":
         logger.info("login success")
     else:
         logger.fatal(f"login fail: {msg}")
         if "3회 오류" in msg:
             logger.critical(f"accouint invalidation warning!")
             input("continue?")
         raise AssertionError("login fail")
Esempio n. 5
0
    def OnReceiveMessage(self, is_system_error, msg_code, msg):
        code = int(msg_code)
        msg = f"OnReceiveMessage: is_system_error={is_system_error}, msg_code={msg_code}, msg={msg}"

        if code < 1000:
            logger.debug(msg)
        elif 1000 <= code < 8000:
            logger.warning(msg)
        else:
            logger.fatal(msg)
Esempio n. 6
0
    def request(
        cls, res, in_block, i: Optional[int] = None,
    ):
        proxy = cls.get_xaquery_event_proxy_from_pool(res)

        @timeout()
        def set_field_data(key_, value_):
            proxy.SetFieldData(f"{res}InBlock{'' if i is None else i}", key_, 0, value_)

        for key, value in in_block.items():
            set_field_data(key, value)
        res = proxy.Request(0)
        if res < 0:
            logger.fatal(f"request fail: {res} -> {cls.get_error_message(res)}")
            post_quit()
            raise AssertionError(res)
        return res
Esempio n. 7
0
    def execute(self, passed_args: list):
        self.cmd_parser.api_instance = APIRequests(passed_args[0])
        response = self.cmd_parser.api_instance.get_current_user()

        body = {}

        try:
            body = response.json()
        except:
            pass
        if response.status_code != 200:
            if response.status_code == 401:
                logger.fatal('RESPONSE 401 - UNAUTHORIZED - INVALID TOKEN')
            else:
                logger.fatal('RESPONSE ' + response.status_code + ': ', body)
            raise Exception('manual interruption')

        logger.info('Authorization successful')
        logger.debug('DATA: ', body)
Esempio n. 8
0
def main():
    global cmd_parser

    argparser.init()
    logger.debug('Verbose mode enabled\nARGV: ', argparser.argv)

    command_stack = _prepare_command_stack(' '.join(argparser.argv.commands))

    if argparser.argv.file:
        file_name = argparser.argv.file[0]
        if not os.path.isfile(file_name):
            logger.fatal('File not found')
            exit(1)

        with open(file_name, 'r') as f_handler:
            command_stack = _prepare_command_stack(f_handler.read())

    logger.debug('COMMANDS: ', command_stack)

    cmd_parser = cmdparser.CommandParser(api.APIRequests(''))
    cmd_parser.register(token.Token)
    cmd_parser.register(cmdhelp.Help)
    cmd_parser.register(select.Select)
    cmd_parser.parse_command_stack(command_stack)
Esempio n. 9
0
def get_secrets(path: str = None):
    """
    Args:
        path (str) <{workingdir/.secrets.json}>: path in which a secret file exists
    Note:
        if there's no secret file, it searches environment variable
    Returns (dict): secret context
    """
    try:
        path = path or os.path.join(os.getcwd(), ".secrets.json")
        with open(path) as f:
            return json.load(f)
    except FileNotFoundError as e:
        logger.warn(f"can't find secret file: {e}")
        try:
            return {
                "ID": os.environ["XING_ID"],
                "PW": os.environ["XING_PW"],
                "DEMO_PW": os.environ["XING_DEMO_PW"],
                "CERT_PW": os.environ["XING_CERT_PW"],
            }
        except KeyError as e:
            logger.fatal(f"can't find secret information: {e}")
            raise AssertionError
Esempio n. 10
0
    def execute(self, passed_args: list):
        if len(passed_args) < 1:
            logger.fatal(
                'MISSING 1. ARGUMENT: GUILD(S)|CHANNEL(S)|ROLE(S)|USER(S)')
            raise Exception('manual interruption')
        # if len(passed_args) < 2:
        #     logger.fatal('MISSING 2. ARGUMENT: ID')
        #     raise Exception('manual interruption')

        api = self.cmd_parser.api_instance

        by_name = False
        if len(passed_args) > 2 and passed_args[1].upper(
        ) == 'BY' and passed_args[2].upper() == 'NAME':
            if len(passed_args) < 4:
                logger.fatal('MISSING ARGUMENT: [NAME]')
                raise Exception('manual interruption')
            by_name = True

        objecttype = passed_args[0].upper()
        identifier = passed_args[1] if len(passed_args) > 1 else None

        if by_name:
            identifier = passed_args[3]

        def __check_args_length(must: int,
                                argname: str,
                                soft: bool = False) -> bool:
            if len(passed_args) < must:
                if not soft:
                    logger.fatal('MISSING ARGUMENT: [%s]' % argname)
                    raise Exception('manual interruption')
                logger.error('MISSING ARGUMENT: [%s]' % argname)

        if objecttype == 'GUILD':
            __check_args_length(2, 'ID')
            response = api.get_guild(identifier, by_name)
            APIRequests.check_status_code(response)
            cache.selected = cache.Selection('GUILD', response.json())

        elif objecttype == 'GUILDS':
            response = api.get_users_guilds()
            api.check_status_code(response)
            cache.selected = cache.Selection('GUILDS', response.json())

        elif objecttype == 'CHANNEL':
            __check_args_length(2, 'ID')
            if by_name and (cache.selected == None
                            or not cache.selected.type == 'GUILD'):
                logger.fatal(
                    'GUILD needs to be selected to select a channel by name')
                raise Exception('manual interruption')
            guild_id = cache.selected.data[
                'id'] if cache.selected != None else ''
            response = api.get_channel(guild_id, identifier, by_name)
            APIRequests.check_status_code(response)
            cache.selected = cache.Selection('CHANNEL', response.json())
            pass

        elif objecttype == 'USER':
            pass

        elif objecttype == 'ROLE':
            pass

        else:
            logger.error('UNSUPPORTED TYPE: ', objecttype)
            raise Exception('manual interruption')

        logger.debug('SELECTED:\n  - TYPE: ', cache.selected.type,
                     '\n  - DATA: ', cache.selected.data)
Esempio n. 11
0
 def OnDisconnect(self):
     logger.fatal("server disconnected")