本文整理汇总了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})
示例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.")