本文整理汇总了Python中db.Db.check_unique_and_insert方法的典型用法代码示例。如果您正苦于以下问题:Python Db.check_unique_and_insert方法的具体用法?Python Db.check_unique_and_insert怎么用?Python Db.check_unique_and_insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Db
的用法示例。
在下文中一共展示了Db.check_unique_and_insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import check_unique_and_insert [as 别名]
#.........这里部分代码省略.........
items = []
for result in results:
if isinstance(result, dict):
name = result.get('name', None)
score = result.get('value', None)
record_id = result.get('record_id', None)
if name is not None and score is not None and record_id is not None:
#name = self.crypt(name, True)
name = base64.b64decode(name)
timestamp = int(time.time())
item = {}
item['name'] = name
item['score'] = score
item['timestamp'] = timestamp
item['record_id'] = record_id
if self.clients[client_id].game_type != 'tetcolor':
item['mode'] = self.clients[client_id].game_type + '_' + mode
else:
item['mode'] = mode
print('current best ' + str(self.clients[client_id].max_score) + '; score ' + str(score))
if int(score) > int(self.clients[client_id].max_score):
print('set this item as best because ' + str(score) + ' gt ' + str(self.clients[client_id].max_score))
self.clients[client_id].max_score = score
self.clients[client_id].best_item = item
items.append(item)
self.db.check_unique_and_insert(items, self.clients[client_id].host)\
.addCallback(self._on_db_insert_response, client_id)\
.addErrback(self._on_db_error, client_id)
return 'wait for db'
def _on_db_insert_response(self, value, client_id):
"""
Callback for DB insert function (class Db).
"""
log.msg('Data inserted for client ' + str(client_id))
self.retrieveTopResults(client_id)
def retrieveTopResults(self, client_id):
"""
Retrieve best results from DB and send to client,
"""
self.db.get_top(client_id, self.clients[client_id].mode, self.clients[client_id].game_type)\
.addCallback(self._on_db_get_top_response, client_id)\
.addErrback(self._on_db_error, client_id)
def _on_db_get_top_response(self, value, client_id):
#log.msg('top10 number ' + str(len(self.clients[client_id].top)))
#log.msg(str(self.clients[client_id].top[0]['name']))
#for result in self.clients[client_id].top:
# log.msg('top item: ' + unicode(result['name']) + ' ' + str(result['score']))
if self.clients[client_id].best_item is None or self.clients[client_id].best_item['score'] is None:
score = 0
self.clients[client_id].best_item = {}
self.clients[client_id].best_item['score'] = 0