const steem = require('steem');
// https://steemit.com/kr-diary/@wonsama/18-07-19-5
let author = 'wonsama';
let permlink = '18-07-19-5';
async function getReplies(author, permlink, output=[]){
let items = await steem.api.getContentRepliesAsync(author, permlink);
let children = [];
for(let item of items){
output.push(item);
if(item.children!=0){
item.c = [];
children.push(getReplies(item.author, item.permlink, item.c));
}
}
await Promise.all(children);
return output;
}
async function getRepliesFlat(author, permlink, output=[]){
let items = await steem.api.getContentRepliesAsync(author, permlink);
let children = [];
for(let item of items){
output.push(item);
if(item.children!=0){
children.push(getReplies(item.author, item.permlink, output));
}
}
await Promise.all(children);
return output;
}
function sortByDate(arr){
arr.sort((a,b)=>{
let gap = a.depth - b.depth;
if(gap==0){
return new Date(a.created).getTime() - new Date(b.created).getTime();
}else{
return gap;
}
});
}
function rePrint(res){
sortByDate(res);
for(let r of res){
console.log(r.depth==1?`\n${r.depth}`:`L ${r.depth}`.padStart(r.depth*2), `@${r.author}`, r.body);
if(r.c){
rePrint(r.c);
}
}
}
getReplies(author, permlink).then(res=>{
rePrint(res);
}).catch(console.error);
외계어인가요?
뭔 뜻인지 몰라 보팅합니다.
외국인이 올까 해서 영어로 태그만 넣었는데...
아무도 안오네요 ㅋㅋㅋ 그냥 한글로 써야지요
본문은 댓글목록 전체 정보를 가져오는 방법입니다
일반적으로는 대댓글 정보는 못가져와서 순환(recursive)방식으로 가져와야되서 ㅋ
그냥 영어라 생각 해 주세요 ㅋ
스팀 api 활용이라니..좋은 글 보고갑니다~
지옥의코드당
네 저도요~
대댓글 코드네요!
역시 원사마님!!