Esempio n. 1
0
def test_parser_conf_init():
    conf()

    assert conf._ParserConf__conf_instance is not None
    assert conf.get('xpath.maintenance_msg') is not None

    cf = conf.get_config()
    assert cf.get('xpath', 'maintenance_msg') is not None
Esempio n. 2
0
File: main.py Progetto: smly/rod
    def __parse_mission_check_user_status(cls, info_data, conts):
        root = lxml.html.fromstring(conts)
        elems = root.xpath(Conf.get('xpath.mission_status'))
        res = {}
        q_stamina = info_data['q_stamina']

        if len(elems) == 12:
            st_pw, st_ex = elems[2], elems[6]
            st_en, st_ca = elems[10], elems[11]
            ca_txt = etree.tostring(st_ca, encoding='UTF-8')

            pw_raw_vals = re.findall("\d+", st_pw.text)
            ex_raw_vals = re.findall("\d+", st_ex.text)
            pw_curr, pw_max = list(map(lambda x: int(x), pw_raw_vals))
            ex_curr, ex_max = list(map(lambda x: int(x), ex_raw_vals))
            card_hold, card_all = list(map(
                lambda x: int(x),
                re.findall(b"\d+", ca_txt)[1:]))

            # Current >= Q-stamina ?
            st_flag = True if pw_curr >= q_stamina else False

            res = {'stamina_cur': pw_curr,
                   'stamina_max': pw_max,
                   'exp_cur': ex_curr,
                   'exp_max': ex_max,
                   'card_cur': card_hold,
                   'card_all': card_all,
                   'st_flag': st_flag}

        info_data.update(res)
        assert res.keys() != 0
Esempio n. 3
0
File: main.py Progetto: smly/rod
    def parse(cls, conts):
        root = lxml.html.fromstring(conts)
        elems = root.xpath(Conf.get('xpath.mission_form'))

        info_data = {}
        MissionParser.__parse_mission_check_detail(info_data, conts)
        MissionParser.__parse_mission_check_user_status(info_data, conts)

        req_action = None
        boss_flag = False
        req_data = {}
        for elem in elems:
            unquote_action = unquote(elem.get("action"))
            action_detail = unquote_action.split("mission")[-1]
            if action_detail == unquote_action:
                # for event quest
                action_detail = "/".join(unquote_action.split('/')[6:])
            action_mode = action_detail.split('/')[1]
            if action_mode == 'sel_questboss':
                boss_flag = True
                continue
            if action_mode != 'check':
                l.debug("Found unknown action mode: %s" % action_mode)
                continue

            # most recent stage
            req_action = elem.get("action")
            subelem_str = etree.tostring(elem, encoding='UTF-8')
            subroot = lxml.html.fromstring(subelem_str)
            subroot_xpath = Conf.get('xpath.mission_input')
            for subelem in subroot.xpath(subroot_xpath):
                elem_name = subelem.get('name')
                if elem_name is None:
                    continue
                req_data.update({elem_name: subelem.get('value')})
            break

        if len(req_data.keys()) <= 0:
            raise exc.MissionParserError

        if len(info_data.keys()) <= 0:
            raise exc.MissionParserError

        return {'req_data': req_data,
                'boss_flag': boss_flag,
                'info': info_data,
                'req_action': req_action}
Esempio n. 4
0
File: main.py Progetto: smly/rod
    def get_service_prefix(cls, conts):
        root = lxml.html.fromstring(conts)
        elems = root.xpath(Conf.get('xpath.battle_form'))
        if len(elems) == 0:
            raise exc.ParserError("No form elements found")
        act = elems[0].get('action')
        m = re.match('http://[^\?]+\?url=http[^a-z]+', act)
        if m is None:
            raise exc.ParserError("Unexpected action attribute found")

        return m.group(0)
Esempio n. 5
0
File: main.py Progetto: smly/rod
    def parse(cls, conts):
        root = lxml.html.fromstring(conts)
        elems = root.xpath(Conf.get('xpath.maintenance_msg'))
        if len(elems) != 0:
            raise exc.ParserError("ToppageParserRuntimeError")

        for elem in root.xpath('//a'):
            link_url = elem.get('href')
            unquote_url = unquote(link_url)
            role_name = unquote_url.split('//')[-1]
            if role_name == 'mypage':
                return link_url[:-6]

        raise exc.ParserError("ToppageParserRuntimeError")
Esempio n. 6
0
File: main.py Progetto: smly/rod
    def parse(cls, conts):
        root = lxml.html.fromstring(conts)
        elems = root.xpath(Conf.get('xpath.battle_form'))
        if len(elems) == 0:
            raise exc.ParserError("BattleConfirmParserRuntimeError")

        form_action = elems[0].get('action')
        elems = root.xpath('//input')
        if len(elems) <= 4:
            raise exc.ParserError("BattleConfirmParserRuntimeError")

        req_data = {}
        for elem in elems[:4]:
            val = (elem.get('value')).encode('utf-8')
            req_data.update({elem.get('name'): val})

        return req_data, form_action
Esempio n. 7
0
File: main.py Progetto: smly/rod
    def parse(cls, conts, *kwargv):
        root = lxml.html.fromstring(conts)
        elems = root.xpath(Conf.get('xpath.mypage_status'))
        if len(elems) != 10:
            raise exc.MypageParserError(
                "Unexpected values found: num of status elemes is %d"
                % len(elems))

        st_raw_vals = re.findall("\d+", elems[1].text)
        pw_raw_vals = re.findall("\d+", elems[4].text)
        if len(st_raw_vals) != 2:
            raise exc.MypageParserError(
                "Unexpected values found: num of st integers is %d"
                % len(st_raw_vals))
        if len(pw_raw_vals) != 2:
            raise exc.MypageParserError(
                "Unexpected values found: num of pw integers is %d"
                % len(pw_raw_vals))

        st_cur, st_max = list(map(lambda x: int(x), st_raw_vals))
        pw_cur, pw_max = list(map(lambda x: int(x), pw_raw_vals))

        st1 = etree.tostring(elems[7], encoding='UTF-8')
        st2 = etree.tostring(elems[9], encoding='UTF-8')
        values1 = list(map(lambda x: int(x), re.findall(b"\d+", st1)))
        values2 = list(map(lambda x: int(x), re.findall(b"\d+", st2)))

        res = {'lv': values1[1],
               'stamina_cur': st_cur,
               'stamina_max': st_max,
               'power_cur': pw_cur,
               'power_max': pw_max,
               'next_lv': values2[1],
               'card_cur': values1[-3],
               'card_max': values1[-2],
               'energy': values1[-1],
               'riv_cur': values2[-3],
               'riv_max': values2[-2],
               'chee_pt': values2[-1]}

        res.update(MypageParser.__parse_event(conts))

        return res
Esempio n. 8
0
File: main.py Progetto: smly/rod
    def __parse_mission_check_detail(cls, info_data, conts):
        root = lxml.html.fromstring(conts)
        elems = root.xpath(Conf.get('xpath.mission_form'))
        for elem in elems:
            unquote_action = unquote(elem.get("action"))
            if len(unquote_action.split("mission")) != 2:
                raise exc.MissionParserError

            action_detail = unquote_action.split("mission")[-1]
            if action_detail == unquote_action:
                # for event quest
                action_detail = "/".join(unquote_action.split('/')[6:])
            action_mode = action_detail.split('/')[1]

            if action_mode == 'check':
                # quest info
                quest_info = etree.tostring(
                    elem.getparent().getprevious(),
                    encoding='UTF-8')
                q_stamina, q_exp, q_energy = list(map(
                    lambda x: int(x),
                    re.findall(b"\d+", quest_info)))
                info_data.update(
                    {'q_stamina': q_stamina,
                     'q_exp': q_exp,
                     'q_energy': q_energy,
                     })

                # progress info
                progress_info = etree.tostring(
                    elem.getparent().getprevious().getprevious(),
                    encoding='UTF-8')
                progress_percent = list(map(
                    lambda x: int(x),
                    re.findall(b"\d+", progress_info)))[0]
                info_data.update(
                    {'progress': progress_percent,
                     })
                break

        # parse check
        if len(info_data.keys()) == 0:
            raise exc.MissionParserError
Esempio n. 9
0
File: main.py Progetto: smly/rod
    def parse(cls, conts):
        prefix = BattleParser.get_service_prefix(conts)
        root = lxml.html.fromstring(conts)
        elems = root.xpath(Conf.get('xpath.battle_status'))

        user_hash = {}
        curr_min_lv = 99999
        curr_min_cost = 99999
        curr_user_id = 999999999
        for elem in elems:
            target_user_page = elem.getchildren()[0]

            user_id_part = unquote(target_user_page.get('href')).split('/')[-1]
            user_id = int(user_id_part)
            user_name = target_user_page.text

            raw_elems = etree.tostring(elem, encoding='UTF-8')

            m_lv = re.search(b'span>[^\d]+(\d+)', raw_elems)
            if m_lv is None:
                raise exc.ParserError("Unexpected action attribute found")

            m_co = re.search(b'span>[^\d]+(\d+)<br', raw_elems)
            if m_co is None:
                raise exc.ParserError("Unexpected action attribute found")

            cost = int(m_co.group(1))
            user_lv = int(m_lv.group(1))

            if curr_min_lv >= user_lv:
                curr_min_lv = user_lv
                if curr_min_cost >= cost:
                    curr_min_cost = cost
                    curr_user_id = user_id

            url = prefix + 'battle%2Fcheck%2F' + str(user_id) + '%2F0'
            user_hash[user_id] = {'user_lv': user_lv,
                                  'cost': cost,
                                  'url': url,
                                  'user_name': user_name}
            l.info("- candidate lv:%s cost:%s name:%s id:%d"
                   % (user_lv, cost, user_name, user_id))

        if len(user_hash.keys()) > 0:
            l.info("- select user_id:%d" % curr_user_id)

        form = {'req_data': {}}
        elems = root.xpath(Conf.get('xpath.battle_form'))
        for elem in elems:
            form['action'] = elem.get('action')
            break
        elems = root.xpath(Conf.get('xpath.battle_input'))
        for elem in elems:
            name = elem.get('name')
            used = set(["del_treasure", "_method"])
            val = (elem.get('value')).encode('utf-8')

            if name in used:
                form['req_data'].update({name: val})

        return curr_user_id, user_hash, form