惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Forbes - Security
Forbes - Security
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
W
WeLiveSecurity
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
PCI Perspectives
PCI Perspectives
Martin Fowler
Martin Fowler
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
WordPress大学
WordPress大学
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
SegmentFault 最新的问题
P
Privacy International News Feed
IT之家
IT之家
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
Hacker News: Ask HN
Hacker News: Ask HN
D
DataBreaches.Net
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Check Point Blog
美团技术团队
Security Latest
Security Latest
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
H
Help Net Security
宝玉的分享
宝玉的分享
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
The Cloudflare Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
爱范儿
爱范儿
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
I
InfoQ
N
News | PayPal Newsroom
TaoSecurity Blog
TaoSecurity Blog

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
2021-03-10 · via 轶哥博客

在《Redash刷新整个仪表盘API》一文中,提到了导出仪表盘中所有的Widget数据为Excel文件的需求。

实现该需求只需要调用官方的API,但是官方API文档对于使用的描述基本没有。

第一步:获取仪表盘数据,得到QueryID

通过请求

GET /api/dashboards/<dashboard_slug>?api_key=<API_KEY>

获取仪表盘数据。

redisdashboard.png

得到类似上图这样的数据。里面具有Widget所有信息。

第二步:通过 QueryIDs 启动查询

遍历widgets,拿到所有需要的item.visualization.query.id,然后挨个请求:

POST /api/queries/<item.visualization.query.id>/results?api_key=<API_KEY>

{
  id: <item.visualization.query.id>,
  parameters: {
    created_at: {
      start: <start> + ' 00:00:00',
      end: <end> + ' 23:59:59'
    }
  }
}

这个请求的含义是“启动新的查询执行或返回缓存的结果”,此API将默认返回缓存的结果。如果没有缓存的结果,则新的执行作业开始,并返回作业对象。要绕过陈旧的缓存,请包含一个名为max_age值为整数秒的参数。如果缓存的结果早于max_age,则缓存将被忽略,并开始新的执行。如果设置max_age0则始终开启新的执行,返回最新的执行结果。

这是一个异步设计的请求,需要对请求结果进行判断。如果返回的结果中含有job字段,说明启动了一个新的作业,否则将返回包含query_result的数据。

查询作业结果:

/api/jobs/<job_id>

  • GET:返回查询任务结果(作业)
    • 可能的状态:
      • 1 ==待处理(等待执行)
      • 2 ==已开始(正在执行)
      • 3 ==成功
      • 4 ==失败
      • 5 ==已取消
    • 状态为成功时,结果包括 query_result_id

也可以不查询结果,不传入max_age: 0的情况下,重复调用接口,则作业完成后必然包含query_result数据。

第三步:拼接文件下载地址

拿到query_result后,拼接如下地址:

https://example.com/api/queries/<item.visualization.query.id>/results/<query_result.id>.xlsx?api_key=<API_KEY>

excel.png此时将可以下载被自动命名的.xlsxExcel文件(跟后台手工下载的一样)。

修改拼接URL的文件名后缀,可以实现TSVCSVJSON文件的下载。

其它

整个过程涉及遍历接口、处理异步设计的接口、根据策略重新调用接口、多文件下载,对刚入门的同学来说是个不错的练手实例。