Redash刷新整个仪表盘API
- 首发:2021-03-10 18:38:37
- 教程
- 3713
转眼间使用Redash已经两年多了,redash
给我的感觉就是省心省事。基础需求都能实现,用户体验很好,升级版本也容易,二次开发也方便简单。
只不过有两个需求redash没有实现:
- API刷新整个仪表盘
- 导出仪表盘中所有的Widget数据为Excel文件
第二个需求,我在《Redash导出仪表盘中所有数据为Excel文件》一文进行了实现说明。
需求分析
Refresh按钮可以设置定时刷新,但是某些情况下我们需要根据条件触发刷新。
或者在内网部署,通过iframe将Share的链接嵌入到OA系统。分享链接不具备刷新功能。
刷新整个仪表盘
官方API文档中就有关于刷新整个仪表盘的说明,指向了这个文件:https://github.com/getredash/redash-toolbelt/blob/master/redash_toolbelt/examples/refresh_dashboard.py
执行上面的代码需要安装Poetry
,可以参考《Poetry快速安装教程》。
安装poetry
后,安装依赖:
poetry install
然后可以执行:
poetry run python3 redash_toolbelt/examples/refresh_dashboard.py https://example.com API_Key slug
实现对相应slug
的仪表盘所有query
进行刷新。
refresh_dashboard.py
代码默认的刷新周期需要手动进行修改:
params = {
"created_at": {
# p.get("name"): fill_dynamic_val(todays_dates, p)
# for p in qry["options"].get("parameters", [])
"start": str(start) + " 00:00:00",
"end": str(end) + " 23:59:59"
}
}
封装命令为API
from flask import Flask
import subprocess, json
app = Flask(__name__)
@app.route("/")
def welcome():
output = subprocess.check_output(["poetry run python3 redash_toolbelt/examples/refresh_dashboard.py https://example.com API_Key slug"], shell = True)
out = output.decode()
return json.dumps({"out": out},ensure_ascii=False)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5001)
访问http://127.0.0.1:5001
即可实现对指定仪表盘进行刷新。
这个实现方法过于简单除暴,只适用于临时使用,正式实现还是参考redash_toolbelt
代码来写吧。
除特别注明外,本站所有文章均为原创。原创文章均已备案且受著作权保护,未经作者书面授权,请勿转载。
打赏
交流区
暂无内容
感谢回复! Clang 在生成时沿用了 GCC 的版本号标识,我是不是可以理解为Clang 18.1.4生成时使用的就是GCC4.8,所以我后续使用gcc 9.4
gcov
就会有不兼容的问题抱歉,这块我也不太清楚,尝试寻求AI的帮助吧。
我在这个过程中遇到了各种问题- -,现在在UDC core: g_serial: couldn't find an available UDC卡住了,请问大佬有什么解决方案吗,还是说我前置的设置就错了呢,> 这个需求很特殊。是可以的,但是比较困难,需要修改驱动配置。
好思路呀!!
关于hex编辑器,网上没找到特别好用的(小白没办法),最后在vscode上扩展一搜hex,第一个安装一下就可以用vscode进行hex编译了