Пример #1
0
Файл: main.py Проект: 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")
Пример #2
0
Файл: main.py Проект: smly/rod
    def __parse_event(cls, conts):
        events = set()

        avail_events = {}
        root = lxml.html.fromstring(conts)
        elems = root.xpath('//a')
        for elem in elems:
            origin_suffix = elem.get('href')
            path_suffix = unquote(origin_suffix)
            path_parts = path_suffix.split('/')
            if len(path_parts) == 6 and path_parts[4] in events:
                event_name = path_parts[4]
                avail_events.update({event_name: origin_suffix})

        return {'event': avail_events}
Пример #3
0
Файл: main.py Проект: 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}
Пример #4
0
Файл: main.py Проект: 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
Пример #5
0
Файл: main.py Проект: 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