资源加载中... loading...

本地存储

Author: FawkesPan, Date: 2020-04-22 18:10:56
Tags: ToolPython

什么东西

FMZ本地存储调用简化工具 关于本地存储,请访问FMZ API文档

有什么用

简化了FMZ本地存储的调用方式,更加的优雅,不用再打_G()

如何使用

导入模板

先复制这个模板到你的策略库,在你要使用这个工具的策略中勾选这个模板

在策略代码中

在策略开头用以下代码建立一个对象

PS = ext.PersistentStorage()

搞定 这个对象PS可以当作普通的Python字典来使用,但是只能存储可以JSON序列化的内容

关于此库

使用 WTFPL – Do What the Fuck You Want to Public License


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# encoding: utf-8
#
#  Persistent Storage for FMZ
#
# Copyright 2020 FawkesPan
# Contact : i@fawkex.me / Telegram@FawkesPan
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
#                    Version 2, December 2004 
#
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> 
#
# Everyone is permitted to copy and distribute verbatim or modified 
# copies of this license document, and changing it is allowed as long 
# as the name is changed. 
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
#   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 
#
#  0. You just DO WHAT THE FUCK YOU WANT TO.
#

class PersistentStorage:
    
    def __init__(self):
        keys = _G('__keys__')
        if isinstance(keys, list):
            self.__keys__ = keys
        else:
            self.__keys__ = []
            self.__setitem__('__keys__', self.__keys__)
        return
    
    def _add_key(self, key):
        if key == '__keys__':
            return
        self.__keys__.append(key)
        self.__setitem__('__keys__', self.__keys__)
        return
        
    def _del_key(self, key):
        if key == '__keys__':
            return
        if key in self.__keys__:
            del self.__keys__[self.__keys__.index(key)]
        self.__setitem__('__keys__', self.__keys__)
        return
    
    def __setitem__(self, key, value):
        _G(key, value)
        self._add_key(key)
        return
    
    def __delitem__(self, key):
        _G(key, None)
        self._del_key(key)
        return
    
    def __getitem__(self, key):
        return _G(key)

    def keys(self):
        return self.__keys__
        

ext.PersistentStorage = PersistentStorage
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6