python - firebase-python,返回 Firebase 最新更新的值?

标签 python firebase

首先我要说的是,我以前从未用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/

相关文章:

python - Scrapy嵌套页面爬取

python - 如何阻止 CharField 在新的发布请求后清除其数据?

python - 无法在 Windows 10 上安装 PIP

javascript - 如何在 Vue 项目中使用 npm 设置 firebase v6.3.4?

firebase - 带有 VueJS 2 数据的 Firestore where 子句

python - 相当于 python 中 hash() 的 Linux 命令

python - 如何将 SwigPyObject 转换为 ctypes void*

android - (android firebase) 确定分页时到达最后一项

firebase - 在 React native 应用程序中实现 Firebase Crashlytics - Android

android - 在 Firebase 中保存数据后 Activity 重启