首先我要说的是,我以前从未用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?
最佳答案
对 python 使用 firebase 似乎有点棘手。 主要缺点是订阅 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 控制台上收到更新后的值,如下所示
[u'put', {u'path': u'/', u'data': u'Hope thie helps'}]
建议:为此目的使用 PubNub 而不是 firebase。
关于python - firebase-python,返回 Firebase 最新更新的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44206484/