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


Python Comment.get_or_create方法代码示例

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


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

示例1: save_snippet

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_or_create [as 别名]
def save_snippet(node, page):

    snippet = Snippet.create(
        page=page,
        text_above=extract_text_above(node),
        text_below=extract_text_below(node),
        header=extract_header_above(node),
        code=extract_code(node),
        line_count=len(node.text.split('\n')),
    )

    for tok_str in extract_tokens(node):
        token, _ = Token.get_or_create(string=tok_str)
        SnippetToken.create(
            snippet=snippet,
            token=token,
        )

    for comment_str in extract_comments(node):
        comment, _ = Comment.get_or_create(string=comment_str)
        SnippetComment.create(
            snippet=snippet,
            comment=comment,
        )

    return snippet
开发者ID:andrewhead,项目名称:StackSkim,代码行数:28,代码来源:get_snippets.py

示例2: get_comments

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_or_create [as 别名]
def get_comments(js_data, article):
    comments = []
    for comment in js_data['comment']:
        comment_id = comment['id']
        content = comment['content']
        create_at = datetime.fromtimestamp(float(comment['create_time']))
        nick_name = comment['nick_name']
        like_num = comment['like_num']
        comment = Comment.get_or_create(
            article, comment_id, content=content, create_at=create_at,
            nick_name=nick_name, like_num=like_num)
        comments.append(comment)
    return comments
开发者ID:SingWang93,项目名称:web_develop,代码行数:15,代码来源:save_article_content.py

示例3: parser_song

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_or_create [as 别名]
def parser_song(song_id, artist):
    tree = get_tree(SONG_URL.format(song_id))
    song = Song.objects.filter(id=song_id)
    r = post(COMMENTS_URL.format(song_id))
    if r.status_code != 200:
        print 'API Error: Song {}'.format(song_id)
        return
    data = r.json()
    if not song:
        for404 = tree.xpath('//div[@class="n-for404"]')
        if for404:
            return

        try:
            song_name = tree.xpath('//em[@class="f-ff2"]/text()')[0].strip()
        except IndexError:
            try:
                song_name = tree.xpath(
                    '//meta[@name="keywords"]/@content')[0].strip()
            except IndexError:
                print 'Fetch limit!'
                time.sleep(10)
                return parser_song(song_id, artist)
        song = Song(id=song_id, name=song_name, artist=artist,
                    comment_count=data['total'])
        song.save()
    else:
        song = song[0]
    comments = []
    for comment_ in data['hotComments']:
        comment_id = comment_['commentId']
        content = comment_['content']
        like_count = comment_['likedCount']
        user = comment_['user']
        if not user:
            continue
        user = User.get_or_create(id=user['userId'], name=user['nickname'],
                                  picture=user['avatarUrl'])
        comment = Comment.get_or_create(id=comment_id, content=content,
                                        like_count=like_count, user=user,
                                        song=song)
        comment.save()
        comments.append(comment)
    song.comments = comments
    song.save()
    time.sleep(1)
    return song
开发者ID:cxiaodian,项目名称:commentbox,代码行数:49,代码来源:parser.py


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