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


Python Node.objects方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import objects [as 别名]
 def post(self):
     if not (session and session.get('uid')):
         return jsonify({'error': 'Not logged in'})
     comment = Comment(text=request.form['text'])
     comment.author = User.objects(id=ObjectId(session.get('uid')))
     comment.save()
     node = Node.objects(id=ObjectId(request.form['nid']))[0]
     nodes.comments.append(comment)
     node.save(cascade=True)
     
 	return jsonify({'success':1})
开发者ID:ArchanPatel890,项目名称:SpaceBubbles,代码行数:13,代码来源:api.py

示例2: main

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import objects [as 别名]
def main(username):
    r = praw.Reddit(user_agent='trollolol v0.1')
    r.config.decode_html_entities = True

    m = MarkovChain('markov-data/%s.chain' % username)

    last_comment = None
    try:
        last_comment = Node.objects(username=username).order_by('-created').first()
        if last_comment:
            print("Checking for new messages.")
            comments = r.get_redditor(username).get_comments(limit=500, params={'after': last_comment.node_id})
        else:
            raise
    except:
        print("No messages fetched yet, doing inital import")
        comments = r.get_redditor(username).get_comments(limit=500)

    for comment in comments:
        try:
            node = Node.objects.get(node_id=comment.name)
        except:
            node = Node(node_id = comment.name, parent_id=comment.parent_id, body=comment.body, created=comment.created, username=username)
            node.save()

    first_comment = Node.objects(username=username).order_by('+created').first()
    if first_comment:
        print("Checking for messages before %s." % first_comment.node_id)
        comments = r.get_redditor(username).get_comments(limit=500, params={'before': first_comment.node_id})

        for comment in comments:
            try:
                node = Node.objects.get(node_id=comment.name)
            except:
                node = Node(node_id = comment.name, parent_id=comment.parent_id, body=comment.body, created=comment.created, username=username)
                node.save()

    comments = Node.objects(username=username).all()

    corpus = []
    for comment in comments:
        corpus.append(comment.body)


    shuffle(corpus)
    if len(corpus) > 0:
        print("We have %i messages to work with. Building new markov corpus now." % len(corpus))
        m.generateDatabase(" ".join(corpus))

        print("Looking for acceptable output for first round of transforms.")
        output = []
        tries = 0 
        while len(output) < 10:
            tries = tries + 1
            result = m.generateString()
            if tries < 100:
                if len(result.split(" ")) >= 10:
                    sys.stdout.write("x")
                    output.append(result)
                else:
                    sys.stdout.write(".")


        print("")

        response = ""
        for result in output:
            response = response + " " + result

        print response
    else:
        print("No comments found.")
开发者ID:gordol,项目名称:reddit_markov_bot,代码行数:74,代码来源:stalk.py


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