本文整理汇总了Python中datastore.DataStore.put方法的典型用法代码示例。如果您正苦于以下问题:Python DataStore.put方法的具体用法?Python DataStore.put怎么用?Python DataStore.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datastore.DataStore
的用法示例。
在下文中一共展示了DataStore.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from datastore import DataStore [as 别名]
# 或者: from datastore.DataStore import put [as 别名]
class Achievements:
__borg_state = {}
__achievements_id = "account_achievements"
def __init__(self, config):
self.__dict__ = self.__borg_state
self.config = config
self.api = GW2_API(config)
self.ds = DataStore(config)
self.render = Render(config)
def _get_current(self):
"""Get the current achievements for the character."""
cheeves = self.api.get("account/achievements")
cheeves_by_id = {}
for cheeve in cheeves:
cheeves_by_id[cheeve.id] = cheeve
return cheeves_by_id
def _get_new_unlock_cheeves(self, old_cheeves, new_cheeves):
"""Given a dict of old and new Achievements, find those that are
newly unlocked.
Returns a tuple of:
(unlocks, newness) where
-unlocks is newly completed cheeves
-newness is new added cheeves
"""
unlocks = []
newness = []
for cheeve in new_cheeves:
if cheeve['id'] not in old_cheeves:
newness.append(cheeve)
elif cheeve['done'] != old_cheeves[cheeve['id']]['done']:
unlocks.append(cheeve)
return (unlocks, newness)
def _get_new_progress_cheeves(self, old_cheeves, new_cheeves):
"""Given a dict of old and new Achievements, find those that have
new progress on them."""
new_prog = []
for cheeve in new_cheeves:
if cheeve.get('current', 0) != \
old_cheeves[cheeve['id']].get('current', 0):
new_prog.append(cheeve)
def update(self, cheeves=None):
"""Will update the datastore with the current cheeves. Intended to be
called once per day, per week, per cycle (whatever).
If 'cheeves' is ommitted, will get the current cheevese via API"""
if cheeves is None:
cheeves = self._get_current()
self.ds.put(self.__achievements_id, cheeves)
示例2: handle_put
# 需要导入模块: from datastore import DataStore [as 别名]
# 或者: from datastore.DataStore import put [as 别名]
def handle_put(seq,key, value):
"""Return a tuple containing True and the message
to send back to the client."""
if key not in POROCESSING:
POROCESSING.append(key)
ds = DataStore(key,value)
if ds.put(seq):
POROCESSING.remove(key)
return (True, 'Key [{}] set to [{}]'.format(key, value))
else:
ds.roll_back(seq)
POROCESSING.remove(key)
return (False, 'Could Not be added')