当前位置: 首页>>代码示例>>Python>>正文


Python Helper.parse_comment方法代码示例

本文整理汇总了Python中helper.Helper.parse_comment方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.parse_comment方法的具体用法?Python Helper.parse_comment怎么用?Python Helper.parse_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helper.Helper的用法示例。


在下文中一共展示了Helper.parse_comment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: board

# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import parse_comment [as 别名]
    def board(self, text):
        arg1 = re.match(' \w+$', text[5:]) # board <code>
        arg2 = re.match(' \w+ \w+$', text[5:]) # board <code> <page>

        if arg1:
            board = arg1.group().strip()
            page = 1
        elif arg2:
            arg2 = arg2.group().strip()
            arg2 = arg2.split(" ") # Split to get real arguments
            board = arg2[0]
            page = arg2[1]
        else:
            return {'content': False, 'status': "Invalid arguments. Use board <code> or board <code> <page>."}

        data = self.api.get_threads(board, page)

        # Determine if an error occured
        if not data['error']:
            self.threads_json = data['result']
        else:
            return data['error']

        # List containing urwid widgets - to be wrapped up by urwid.Pile
        content = [
            urwid.Text([("\nDisplaying page "), (('highlight'), str(page)), " of /", (('highlight'), str(board)), "/.\n"])
        ]

        if self.threads_json:
            self.current_threads['board'] = board
            del self.current_threads['list'][:] # Reset previous temporary data

            data = json.loads(self.threads_json)
            for index, post in enumerate(data['threads'], 1): # index starting from 1 to open threads without specifying full id (see: open <index>)

                self.current_threads['list'].append(post['posts'][0]['no']) # Quick opening
                _header = [
                    ('highlight', "({}) ".format(index)),
                    ('number', "No. {} ".format(post['posts'][0]['no'])),
                    ('time', "{}".format(post['posts'][0]['now']))
                ]

                # Check for empty comment
                if "com" in post['posts'][0]:
                    _text = Helper.parse_comment(post['posts'][0]['com'])
                else:
                    _text = "- no comment -\n"

                content.append(urwid.Padding(urwid.Text(_header), 'left', left=0))
                content.append(urwid.Padding(urwid.Text(_text), 'left', left=4)) # Indent text content from header

        return {'content': urwid.Pile(content), 'status': "Displaying page {} of /{}/".format(page, board)}
开发者ID:gimu,项目名称:chancli,代码行数:54,代码来源:state.py

示例2: thread

# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import parse_comment [as 别名]
    def thread(self, text):
        """Open thread by specifying board and id."""
        arg = re.match(' \w+ \w+$', text[6:]) # thread <board> <id>

        if arg:
            arg = arg.group().strip()
            arg = arg.split(" ") # Split to get real arguments

            board = arg[0]
            thread_id = arg[1]
        else:
            return {'content': False, 'status': "Invalid arguments. Use thread <board> <id>."}

        data = self.api.get_thread(board, thread_id)

        # Determine if an error occured
        if not data['error']:
            self.thread_json = data['result']
        else:
            return data['error']

        # List containing urwid widgets - to be wrapped up by urwid.Pile
        content = [
            urwid.Text([("\nDisplaying thread "), (('highlight'), str(thread_id)), " in /", (('highlight'), str(board)), "/.\n"])
        ]

        if self.thread_json:
            data = json.loads(self.thread_json)
            for post in data["posts"]:
                _header = [
                    ('number', "No. {} ".format(post['no'])),
                    ('time', "{}".format(post['now']))
                ]

                if "com" in post:
                    _text = Helper.parse_comment(post['com'])
                else:
                    _text = "- no comment -\n"

                content.append(urwid.Padding(urwid.Text(_header), 'left', left=0))
                content.append(urwid.Padding(urwid.Text(_text), 'left', left=4)) # Indent text content from header

        return {'content': urwid.Pile(content), 'status': "Displaying thread {} in /{}/".format(thread_id, board)}
开发者ID:gimu,项目名称:chancli,代码行数:45,代码来源:state.py


注:本文中的helper.Helper.parse_comment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。