本文整理匯總了Python中model.Node.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Node.get方法的具體用法?Python Node.get怎麽用?Python Node.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類model.Node
的用法示例。
在下文中一共展示了Node.get方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: addNodes
# 需要導入模塊: from model import Node [as 別名]
# 或者: from model.Node import get [as 別名]
def addNodes(nodes):
added = []
for id in nodes:
node,revision,tags = getNode(id)
node['version'] = node['vid']
node['user'] = node['uid']
node['id'] = node['nid']
revision['user'] = revision['uid']
revision['id'] = revision['vid']
revision['node'] = revision['nid']
del(node['status'])
del(node['uid'])
del(node['nid'])
del(node['vid'])
del(revision['uid'])
del(revision['nid'])
del(revision['vid'])
# add the nodes
try:
dbnode = Node.get(node['id'])
del(node['id'])
dbnode.set(**node)
except SQLObjectNotFound:
dbnode = Node(**node)
try:
dbnoder = NodeRevision.get(revision['id'])
del(revision['id'])
dbnoder.set(**revision)
except SQLObjectNotFound:
dbnoder = NodeRevision(**revision)
# add the termnodes
for tag in tags:
tag['node'] = tag['nid']
tag['term'] = tag['tid']
del(tag['nid'])
del(tag['tid'])
try:
dbtag = Term.get(tag['term'])
except SQLObjectNotFound:
dbtag = addTags([tag['term']])[0]
terms = list(TermNode.selectBy(node=dbnode,term=dbtag))
if not terms:
term = TermNode(**tag)
else:
term = terms[0]
print "Node %d made!" % id
added.append(id)
return added
示例2: syncNodes
# 需要導入模塊: from model import Node [as 別名]
# 或者: from model.Node import get [as 別名]
def syncNodes():
print "syncing nodes"
tags_checked = []
users_checked = []
nodes_checked = []
tags_new = []
users_new = []
nodes_new = []
for node in getNewNodes():
tid = node['tid']
nid = node['nid']
changed = node['changed']
uid = node['uid']
if tid not in tags_checked:
try:
term = Term.get(tid)
except SQLObjectNotFound:
tags_new.append(tid)
tags_checked.append(tid)
if uid not in users_checked:
try:
node = User.get(uid)
except SQLObjectNotFound:
users_new.append(uid)
users_checked.append(uid)
if nid not in nodes_checked:
try:
node = Node.get(nid)
if node.changed < changed:
nodes_new.append(nid)
except SQLObjectNotFound:
nodes_new.append(nid)
nodes_checked.append(nid)
hub.begin()
# add new db information
addTags(tags_new)
addUsers(users_new)
nodes = addNodes(nodes_new)
setWeight()
hub.commit()
return nodes