加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python firebase实时监听器

发布时间:2020-12-20 11:03:58 所属栏目:Python 来源:网络整理
导读:嗨,我是 python中的新手. 我想在Firebase DB上实现监听器. 当我在DB上更改一个或多个参数时,我的 Python代码必须做一些事情. 我该怎么做? 非常感谢 我的数据库就像从001到200的简单数据列表: "remote-controller"001 - 000002 - 020003 - 230 我的代码是:
嗨,我是 python中的新手.
我想在Firebase DB上实现监听器.
当我在DB上更改一个或多个参数时,我的 Python代码必须做一些事情.
我该怎么做?
非常感谢

我的数据库就像从001到200的简单数据列表:

"remote-controller"
001 -> 000
002 -> 020
003 -> 230

我的代码是:

from firebase import firebase
firebase = firebase.FirebaseApplication('https://remote-controller.firebaseio.com/',None)
result = firebase.get('003',None)
print result

解决方法

看起来现在支持这种情况(2018年10月):虽然它没有在 the ‘Retrieving Data’ guide中记录,但您可以在 the API reference中找到所需的功能.我测试了它,它的工作原理如下:

def listener(event):
    print(event.event_type)  # can be 'put' or 'patch'
    print(event.path)  # relative to the reference,it seems
    print(event.data)  # new data at /reference/event.path. None if deleted

firebase_admin.db.reference('my/data/path').listen(listener)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读