python firebase realtime listener

前端 未结 6 1072
离开以前
离开以前 2020-12-05 16:47

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. Ho

6条回答
  •  -上瘾入骨i
    2020-12-05 17:36

    As Peter Haddad suggested, you should use Pyrebase for achieving something like that given that the python SDK still does not support realtime event listeners.

    import pyrebase
    
    config = {
        "apiKey": "apiKey",
        "authDomain": "projectId.firebaseapp.com",
        "databaseURL": "https://databaseName.firebaseio.com",
        "storageBucket": "projectId.appspot.com"
    }
    
    firebase = pyrebase.initialize_app(config)
    
    db = firebase.database()
    
    def stream_handler(message):
        print(message["event"]) # put
        print(message["path"]) # /-K7yGTTEp7O549EzTYtI
        print(message["data"]) # {'title': 'Pyrebase', "body": "etc..."}
    
    
    my_stream = db.child("posts").stream(stream_handler)
    

提交回复
热议问题