python firebase实时监听器 [英] python firebase realtime listener

查看:75
本文介绍了python firebase实时监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手. 我想在Firebase数据库上实现侦听器. 当我在数据库上更改一个或多个参数时,我的Python代码必须执行某些操作. 我该怎么做? 非常感谢

Hi there I'm new in python. I would like to implement the listener on my Firebase DB. When I change one or more parameters on the DB my Python code have to do something. How can I do it? Thank a lot

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

my db is like simple list of data from 001 to 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月)似乎已支持此方法:尽管未在,您可以在

It looks like this is supported now (october 2018): although it's not documented in the 'Retrieving Data' guide, you can find the needed functionality in the API reference. I tested it and it works like this:

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)

这篇关于python firebase实时监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆