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


Python DataStore.put方法代码示例

本文整理汇总了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)
开发者ID:criswell,项目名称:gw2-widgets,代码行数:62,代码来源:achievements.py

示例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')
开发者ID:anupkalburgi,项目名称:dbreplication-sqlite,代码行数:16,代码来源:handlers.py


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