firebasepython,将最新更新的值返回到Firebase?

2024-06-16 09:35:28 发布

您现在位置:Python中文网/ 问答频道 /正文

让我先说,我以前从来没有用python编写过代码。在

我正在考虑使用https://github.com/shariq/firebase-python连接到我的Firebase数据库。我正在使用IFTTT将数据从另一个源推送到Firebase。当更新发生时,我希望它自动推送到我的python代码中。在

我有以下内容:

import firebase
updatesUrl = 'baseball/updates'
updatesSubscription = firebase.subscriber(updatesUrl, refreshDisplay())

def refreshDisplay():
    # how do i get the value of the last update here?

Tags: the数据代码httpsimportgithubcom数据库
1条回答
网友
1楼 · 发布于 2024-06-16 09:35:28

使用firebase for python似乎有点棘手。 主要的缺点是订阅URL后,订阅者每15分钟轮询firebase一次。在

以下是您可以使用代码执行的操作:

import firebase
updatesUrl = 'https://<app-name>.firebaseio.com/baseball/update.json'
updatesSubscription = firebase.subscriber(updatesUrl, refreshDisplay)

def refreshDisplay(json_data):
    j = json.loads(json.dumps(json_data))  
    print j

在执行python代码之后,打开firebase数据库,并对要监视的字段进行一些更改。 大约15分钟后,您将在python控制台上收到更新的值,比如

^{pr2}$

建议:使用PubNub而不是firebase。在

相关问题 更多 >