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


Python DataStore.get方法代码示例

本文整理汇总了Python中datastore.DataStore.get方法的典型用法代码示例。如果您正苦于以下问题:Python DataStore.get方法的具体用法?Python DataStore.get怎么用?Python DataStore.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在datastore.DataStore的用法示例。


在下文中一共展示了DataStore.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_get

# 需要导入模块: from datastore import DataStore [as 别名]
# 或者: from datastore.DataStore import get [as 别名]
def handle_get(key):
    """Return a tuple containing True if the key exists and the message
    to send back to the client."""
    if key not in POROCESSING:
        ds = DataStore()
        data = ds.get(key)
        if data:
            return(True, (data[0],data[1]))
    return(False, 'ERROR: Key [{}] not found'.format(key))
开发者ID:anupkalburgi,项目名称:dbreplication-sqlite,代码行数:11,代码来源:handlers.py

示例2: handle_delete

# 需要导入模块: from datastore import DataStore [as 别名]
# 或者: from datastore.DataStore import get [as 别名]
def handle_delete(seq,key):
    """Return a tuple containing True if the key could be deleted and
    the message to send back to the client.

    use datastore.get and then before doing doing datastore.delete
    """
    ds = DataStore()
    if ds.get(key):
        POROCESSING.append(key)
        if ds.delete(seq,key):   
            POROCESSING.remove(key)
            return (True,'Done')
        else:
            ds.roll_back(seq) 
            POROCESSING.remove(key)
    return (False,'ERROR: Key [{}] not found and could not be deleted'.format(key))
开发者ID:anupkalburgi,项目名称:dbreplication-sqlite,代码行数:18,代码来源:handlers.py

示例3: __init__

# 需要导入模块: from datastore import DataStore [as 别名]
# 或者: from datastore.DataStore import get [as 别名]
class Colors:
    __borg_state = {}
    __account_colors_id = "account_colors"
    __color_id = "colors"

    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 colorize(self):
        """Generate the embedded pages pertaining to an account's colors"""

        # Start by getting all the colors this account has
        my_colors = self.api.get("account/dyes")

        # Now, load previous color data
        old_colors = self.ds.get(self.__account_colors_id)

        # Find new colors
        new_colors = set(my_colors) - set(old_colors.get('colors', {}))

        # Now, obtain color details on each color
        temp_colors = self.api.get_with_limit("colors",
                { "ids" : my_colors }, "ids", 200)
        listings = self.api.get_with_limit("commerce/listings",
                { "ids" :  [c['item'] for c in temp_colors] }, "ids", 200)
        colors_by_id = {}
        colors_by_set = {}
        for c in temp_colors:
            colors_by_id[c['item']] = c
            cat = c['categories'][-1]
            if cat not in colors_by_set:
                colors_by_set[cat] = []
            colors_by_set[cat].append(c['item'])
        listings_by_id = {}
        for l in listings:
            listings_by_id[l['id']] = l
        data = {}
        color_library = {}
        total_value = 0

        rarities = []
        for rarity in colors_by_set.keys():
            if rarity not in color_library:
                color_library[rarity] = []
            if rarity not in rarities:
                rarities.append(rarity)

            colors_by_set[rarity].sort()
            for c in colors_by_set[rarity]:
                cost = 0
                if c in listings_by_id:
                    cost = listings_by_id[c]['sells'][0]['unit_price']
                color_library[rarity].append({
                        "dye" : colors_by_id[c],
                        "price" : cost
                        })
                total_value += cost

        # Hackish way to ensure we sort rarities right
        rarities_sorted = []
        if "Starter" in rarities:
            rarities_sorted.append("Starter")
            rarities.remove("Starter")
        if "Common" in rarities:
            rarities_sorted.append("Common")
            rarities.remove("Common")
        if "Uncommon" in rarities:
            rarities_sorted.append("Uncommon")
            rarities.remove("Uncommon")
        if "Rare" in rarities:
            rarities_sorted.append("Rare")
            rarities.remove("Rare")
        if len(rarities) > 0:
            rarities.sort()
            rarities_sorted.extend(rarities)

        data = {
            'colors' : color_library,
            'value' : total_value,
            'rarities' : rarities_sorted
            }

        # Finally, render
        return self.render.render(self.__color_id, data)
开发者ID:criswell,项目名称:gw2-widgets,代码行数:90,代码来源:colors.py


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