V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ccdjh
V2EX  ›  Python

保存使用 token 数据的小工具

  •  
  •   ccdjh ·
    ccdjh · 2016-07-04 14:48:38 +08:00 · 2695 次点击
    这是一个创建于 2825 天前的主题,其中的信息可能已经有所发展或是发生改变。

    调试 token 的快速使用

    例如微信开发,获取 token:

    {"access_token":"ACCESS_TOKEN","expires_in":7200}
    

    临时处理 expires_in 还是挺烦心的。搭建数据库更显得浪费时间。

    我把野狗的产品包装一下,做个小工具,这 2 个月使用还是挺方便的。例如解决上面的问题:

    expires_set(name,value,expires)设置值,和过期时间

    expires_get(name)获取值

    注册 wilddog 账号 www.wilddog.com

    pip install boxwilddog
    

      from boxwilddog import boxwilddog
    
      url = 'You Wilddog URL'
      auth = 'You Wilddog AUTH'
      #wild-horse-10086.wilddogio.com -> url = 'wild-horse-10086'
    
      box = boxwilddog.Box(url,auth)
      box_expires_set = box.expires_set('weixintoken','token','1000')
      #>>>'["weixintoken","token","1000"]'
      #参数必须是字符串,三个参数。第一个是 name,第二个是 value ,第二个是 expires
      #返回值:是列表形式的字符串
    
      box_expires_get = box.expires_get('weixintoken')
      #>>>u'["weixintoken","token","902"]'
      #参数必须是字符串,一个参数,第一个是 name 。
      #返回值:是列表形式的字符串
    

    更多可以看 github 的文档, https://github.com/ccdjh/boxwilddog

    3 条回复    2016-07-05 17:38:03 +08:00
    ooTwToo
        1
    ooTwToo  
       2016-07-04 15:03:24 +08:00 via iPhone
    我存 redis
    lslqtz
        2
    lslqtz  
       2016-07-04 19:36:41 +08:00 via iPhone
    我存 memcache 。
    ccdjh
        3
    ccdjh  
    OP
       2016-07-05 17:38:03 +08:00
    @ooTwToo

    可以使用这个,生成 json 数据:
    from boxwilddog import boxwilddog

    class WilddogJson(boxwilddog.Model):
    a_auth = boxwilddog.AuthProperty()
    a_time = boxwilddog.TimeProperty()
    a1 = boxwilddog.StringProperty()

    s = WilddogJson()
    s_json = s.value

    #>>>{'a_auth': '1467536273uIHwar63qmG3XetwDAR6', 'a_time': '1467536273', 'a1': 'none'}
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5410 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:48 · PVG 16:48 · LAX 01:48 · JFK 04:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.