我想运行一个简单的脚本,它以JSON格式从Trello获得所有卡片等,其中的数据和URL看起来如下:https://trello.com/b/Vqrkz3KO.json。我想要自动化出口板的过程。
但是Trello不允许我这样做,所以我必须从API中这样做:
`/1/boards/${board.id}`, {fields: "all",actions: "all",action_fields: "all",activities_limit: 1000,cards: "all",card_fields: "all",card_attachments: true,labels: "all",lists: "all",list_fields: "all",members: "all",member_fields: "all",checklists: "all",checklist_fields: "all", organization: false它能做我想做的事情,但是我想要得到卡片的板有1000多个活动。那我怎么才能得到所有的活动?它只获取1000个活动/卡片。另外,我不能只获取上面的URL,因为出于某些原因,您不能使用api来按照this question来获取它。这个问题没有回答我的问题,我想超过1000张卡片,但如果你这样做,你会出现一个错误,说你不能。
发布于 2020-07-19 08:12:55
编辑2:最后,我使用了API &用于HTTPS请求的ID生成器,并使用了提供的&before=参数。&before=参数使用日期作为参数,因此我必须从一个请求中获取最后一个操作,从中获取日期,并将其提供给& provide参数。然后,对于每个有1000个元素的数组元素,我会弹出最后一个元素,因为我最终会得到重复的操作。
现在,我得到了类似于这样的操作:[[actions],[actions],[actions],[actions]]等等,所以我使用了Merge/flatten an array of arrays的答案来实现所有的[actions],然后我使用括号符号object["key"] = value来设置/替换来自HTTPS请求的操作,它变成了一个非常大的文件,并且花了相当长的时间来生成这个文件,它出现在99.5 MB周围。
这是我的整个index.js测试文件:
const https = require('https');
const fs = require('fs');
var boardinfo = "";
https.get({
hostname: 'trello.com',
path: `/b/....json`,
headers: {'User-Agent': `${Math.random().toString(16).substring(2,16)}`}
}, (r) => {
var data = "";
r.on('data', (d) => {
data+=d;
})
r.on('close', () => {
boardinfo = JSON.parse(data);
});
})
var actions = [];
(function untilDeath(beforeval) {
https.get({
hostname: 'api.trello.com',
path: `/1/boards/.../actions?limit=1000${beforeval ? `&before=${beforeval}` : ``}`,
headers: {'User-Agent': `${Math.random().toString(16).substring(2,16)}`}
}, (r) => {
var cmpdta = "";
r.on('data', (d) => {
cmpdta+=d;
})
r.on('close', () => {
cmpdta = JSON.parse(cmpdta);
if(cmpdta.length < 1000) {
if(cmpdta.length) actions.push(cmpdta);
return makeFile(info, [].concat.apply([], actions), fileName);
} else
untilDeath(cmpdta[999].date);
cmpdta.pop();
actions.push(cmpdta);
});
r.on('error', () => {
throw new Error('Error');
});
});
})();
function makeFile(trelloBoard, actions) {
trelloBoard["actions"] = actions;
fs.createWriteStream('./full-board.json');
fs.writeFile(`./full-board.json`, JSON.stringify(trelloBoard, null, `\t`), (c) => {
if(c) console.log(c);
});
}编辑:令人失望的是,这也只获取1000个操作,即使手动保存JSON文件,它仍然提供1000个操作。
我通过HTTPS User-Agent头轻松地解决了这个问题。
const https = require('https');
https.get({
hostname: 'trello.com',
path: '/b/....json',
headers: {'User-Agent': 'some-random-user-agent'}
}, (r) => {
var str = "";
r.on('data', (d) => {str+=d});
r.on('close', () => {console.log(str)})
})https://stackoverflow.com/questions/62237952
复制相似问题